@ledgerhq/context-module 0.0.0-ledger-button-20250821163751 → 0.0.0-ledger-button-20250905011628

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.
Files changed (37) hide show
  1. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
  2. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
  3. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  4. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  5. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +1 -1
  6. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +1 -1
  7. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  8. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +1 -1
  9. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  10. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  11. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  12. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  13. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  14. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +1 -1
  15. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  16. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +1 -1
  17. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
  18. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
  19. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  20. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  21. package/lib/esm/src/transaction/data/HttpProxyDataSource.js +1 -1
  22. package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +1 -1
  23. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  24. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +1 -1
  25. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  26. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  27. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  28. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  29. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  30. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +1 -1
  31. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  32. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +1 -1
  33. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -1
  34. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +1 -3
  35. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  36. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  37. package/package.json +3 -3
@@ -1,2 +1,2 @@
1
- var p=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=(a,i,r,t)=>{for(var e=t>1?void 0:t?s(i,r):i,o=a.length-1,f;o>=0;o--)(f=a[o])&&(e=(t?f(i,r,e):f(e))||e);return t&&e&&p(i,r,e),e},n=(a,i)=>(r,t)=>i(r,t,a);import{inject as C,injectable as k}from"inversify";import{pkiTypes as P}from"../../pki/di/pkiTypes";let c=class{_dataSource;constructor(i){this._dataSource=i}async loadCertificate(i){return(await this._dataSource.fetchCertificate(i)).caseOf({Right:t=>t,Left:t=>{throw t instanceof Error?t:new Error(String(t))}})}};c=m([k(),n(0,C(P.PkiCertificateDataSource))],c);export{c as DefaultPkiCertificateLoader};
1
+ var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=(a,t,e,r)=>{for(var i=r>1?void 0:r?s(t,e):t,o=a.length-1,f;o>=0;o--)(f=a[o])&&(i=(r?f(t,e,i):f(i))||i);return r&&i&&n(t,e,i),i},p=(a,t)=>(e,r)=>t(e,r,a);import{inject as u,injectable as C}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";let c=class{_dataSource;constructor(t){this._dataSource=t}async loadCertificate(t){return(await this._dataSource.fetchCertificate(t)).orDefault(void 0)}};c=m([C(),p(0,u(k.PkiCertificateDataSource))],c);export{c as DefaultPkiCertificateLoader};
2
2
  //# sourceMappingURL=DefaultPkiCertificateLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n return certificate.caseOf({\n Right: (cert) => cert,\n Left: (err) => {\n throw err instanceof Error ? err : new Error(String(err));\n },\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,YAAAC,MAAgB,oBAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAIrC,OAFE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAEvC,OAAO,CACxB,MAAQC,GAASA,EACjB,KAAOC,GAAQ,CACb,MAAMA,aAAe,MAAQA,EAAM,IAAI,MAAM,OAAOA,CAAG,CAAC,CAC1D,CACF,CAAC,CACH,CACF,EAvBaJ,EAANK,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAS,wBAAwB,IAJhCT",
6
- "names": ["inject", "injectable", "pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "cert", "err", "__decorateClass", "injectable", "__decorateParam", "inject", "pkiTypes"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n // TODO add logs error with certificate.left()\n return certificate.orDefault(undefined);\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,YAAAC,MAAgB,oBAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAKrC,OAHE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAGvC,UAAU,MAAS,CACxC,CACF,EAnBaF,EAANG,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAS,wBAAwB,IAJhCP",
6
+ "names": ["inject", "injectable", "pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "__decorateClass", "injectable", "__decorateParam", "inject", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as l,Right as n}from"purify-ts";import{DefaultPkiCertificateLoader as i}from"../../pki/domain/DefaultPkiCertificateLoader";import{KeyId as o}from"../../pki/model/KeyId";import{KeyUsage as c}from"../../pki/model/KeyUsage";describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},t={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},a={fetchCertificate:vi.fn().mockResolvedValue(n(t))},f=await new i(a).loadCertificate(e);expect(f).toEqual(t),expect(a.fetchCertificate).toHaveBeenCalledWith(e)}),it("throws when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},t=new Error("failed"),a={fetchCertificate:vi.fn().mockResolvedValue(l(t))},r=new i(a);await expect(r.loadCertificate(e)).rejects.toThrow(t),expect(a.fetchCertificate).toHaveBeenCalledWith(e)})})});
1
+ import{Left as n,Right as l}from"purify-ts";import{DefaultPkiCertificateLoader as r}from"../../pki/domain/DefaultPkiCertificateLoader";import{KeyId as o}from"../../pki/model/KeyId";import{KeyUsage as c}from"../../pki/model/KeyUsage";describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},t={fetchCertificate:vi.fn().mockResolvedValue(l(a))},i=await new r(t).loadCertificate(e);expect(i).toEqual(a),expect(t.fetchCertificate).toHaveBeenCalledWith(e)}),it("Returns undefined when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},a=new Error("failed"),t={fetchCertificate:vi.fn().mockResolvedValue(n(a))},i=await new r(t).loadCertificate(e);expect(i).toBeUndefined(),expect(t.fetchCertificate).toHaveBeenCalledWith(e)})})});
2
2
  //# sourceMappingURL=DefaultPkiCertificateLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"throws when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n await expect(loader.loadCertificate(certificateInfos)).rejects.toThrow(\n fetchError,\n );\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,+BAAAC,MAAmC,2CAC5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMG,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBN,EAAMK,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAIN,EAA4BK,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMM,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBP,EAAKS,CAAU,CAAC,CAC9D,EACMC,EAAS,IAAIR,EAA4BK,CAAU,EAGzD,MAAM,OAAOG,EAAO,gBAAgBL,CAAgB,CAAC,EAAE,QAAQ,QAC7DI,CACF,EACA,OAAOF,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "DefaultPkiCertificateLoader", "KeyId", "KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError", "loader"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"Returns undefined when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n const result = await loader.loadCertificate(certificateInfos);\n expect(result).toBeUndefined();\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,+BAAAC,MAAmC,2CAC5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMG,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBN,EAAMK,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAIN,EAA4BK,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMM,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBP,EAAKS,CAAU,CAAC,CAC9D,EAIMD,EAAS,MAHA,IAAIN,EAA4BK,CAAU,EAG7B,gBAAgBF,CAAgB,EAC5D,OAAOG,CAAM,EAAE,cAAc,EAC7B,OAAOD,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "DefaultPkiCertificateLoader", "KeyId", "KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?f(e,t):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&P(e,t,o),o},m=(i,e)=>(t,r)=>e(t,r,i);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as a,Right as y}from"purify-ts";import{configTypes as E}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as c}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let d=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:t,chainId:r,challenge:o}){let n;try{n=(await p.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken},data:{proxy:e,data:t,challenge:o}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return n?this.isProxyDelegateCallDto(n)?y({delegateAddresses:n.addresses,signedDescriptor:n.signedDescriptor}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:t}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${t}/contract/proxy/${e}`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${t}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${t}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(t=>typeof t=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};d=l([u(),m(0,D(E.Config))],d);export{d as HttpProxyDataSource};
1
+ var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?f(e,t):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&P(e,t,o),o},m=(i,e)=>(t,r)=>e(t,r,i);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as a,Right as y}from"purify-ts";import{configTypes as E}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as c}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let d=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:t,chainId:r,challenge:o}){let n;try{n=(await p.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken},data:{proxy:e,data:t,challenge:o}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return n?this.isProxyDelegateCallDto(n)?y({delegateAddresses:n.addresses,signedDescriptor:n.signedDescriptor}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:t}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${t}/contract/proxy/${e}`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${t}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${t}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(t=>typeof t=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};d=l([u(),m(0,D(E.Config))],d);export{d as HttpProxyDataSource};
2
2
  //# sourceMappingURL=HttpProxyDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpProxyDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n challenge: string;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n challenge,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n challenge,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({\n delegateAddresses: dto.addresses,\n signedDescriptor: dto.signedDescriptor,\n });\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"addresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.addresses) &&\n value.addresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n challenge: string;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n challenge,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n challenge,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({\n delegateAddresses: dto.addresses,\n signedDescriptor: dto.signedDescriptor,\n });\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"addresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.addresses) &&\n value.addresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
5
5
  "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAOC,MAAa,qBA2Bb,IAAMC,EAAN,KAAqD,CAC1D,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,SAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyE,CACvE,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAMC,EAAM,QAA8B,CACzD,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,2BACpE,QAAS,CACP,CAACI,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,EACA,KAAM,CACJ,MAAOR,EACP,KAAMC,EACN,UAAAE,CACF,CACF,CAAC,GACc,IACjB,MAAiB,CACf,OAAOM,EACL,IAAI,MACF,qEACF,CACF,CACF,CAEA,OAAKL,EAQA,KAAK,uBAAuBA,CAAG,EAQ7BM,EAAM,CACX,kBAAmBN,EAAI,UACvB,iBAAkBA,EAAI,gBACxB,CAAC,EAVQK,EACL,IAAI,MACF,8FAA8FT,CAAY,aAAaE,CAAO,EAChI,CACF,EAZOO,EACL,IAAI,MACF,mEAAmET,CAAY,aAAaE,CAAO,EACrG,CACF,CAeJ,CAEA,MAAa,8BAA8B,CACzC,aAAAF,EACA,QAAAE,CACF,EAEE,CACA,IAAIE,EACJ,GAAI,CASFA,GARiB,MAAMC,EAAM,QAAuC,CAClE,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,mBAAmBF,CAAY,GACnG,QAAS,CACP,CAACM,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GACc,IACjB,MAAiB,CACf,OAAOC,EACL,IAAI,MACF,6EACF,CACF,CACF,CAEA,OAAKL,EAQA,KAAK,gCAAgCA,CAAG,EAQtCM,EAAM,CAAE,sBAAuBN,EAAI,qBAAsB,CAAC,EAPxDK,EACL,IAAI,MACF,uGAAuGT,CAAY,aAAaE,CAAO,EACzI,CACF,EAZOO,EACL,IAAI,MACF,mEAAmET,CAAY,aAAaE,CAAO,EACrG,CACF,CAYJ,CAKQ,uBACNS,EAC+B,CAC/B,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,cAAeA,GACf,qBAAsBA,GACtB,MAAM,QAAQA,EAAM,SAAS,GAC7BA,EAAM,UAAU,MAAOC,GAAY,OAAOA,GAAY,QAAQ,GAC9D,OAAOD,EAAM,kBAAqB,QAEtC,CAKQ,gCACNA,EACwC,CACxC,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,iBAAkBA,GAClB,0BAA2BA,GAC3B,aAAcA,GACd,OAAOA,EAAM,cAAiB,UAC9B,OAAOA,EAAM,uBAA0B,UACvC,OAAOA,EAAM,UAAa,UAC1BA,EAAM,SAAS,OAAS,CAE5B,CACF,EAxIab,EAANe,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBnB",
6
6
  "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "challenge", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Left", "Right", "value", "address", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},i={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},d={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v1/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
1
+ import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},i={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},d={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
2
2
  //# sourceMappingURL=HttpProxyDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpProxyDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type { ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\nimport type {\n GetProxyDelegateCallParam,\n GetProxyImplementationAddressParam,\n ProxyDataSource,\n} from \"./HttpProxyDataSource\";\nimport { HttpProxyDataSource } from \"./HttpProxyDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpProxyDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n\n let datasource: ProxyDataSource;\n const defaultParams: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 1,\n challenge: \"0x1234567890abcdef\",\n };\n const defaultImplementAddressParams: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 1,\n };\n const delegateProxyResponse: ProxyDelegateCallDto = {\n addresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n };\n const implementationAddressResponse: ProxyImplementationAddress = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n };\n const implementationAddressDto: ProxyImplementationAddressDto = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n standard: \"proxy\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n datasource = new HttpProxyDataSource({\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig);\n });\n\n describe(\"getDelegateProxy\", () => {\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(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should return the delegate proxy response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: delegateProxyResponse,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Right({\n delegateAddresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\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(\"fail\"));\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: { foo: \"bar\" } });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 137, // Polygon\n challenge: \"0x1234567890abcdef\",\n };\n\n // WHEN\n await datasource.getProxyDelegateCall(paramsWithDifferentChainId);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: \"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/delegate\",\n }),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n });\n\n describe(\"getImplementAddress\", () => {\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(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should make a GET request to the correct URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v1/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n paramsWithDifferentChainId,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should return the implementation address response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: implementationAddressDto,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(Right(implementationAddressResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"network error\"));\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch implementation address\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: { invalid: \"data\" },\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n });\n});\n"],
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type { ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\nimport type {\n GetProxyDelegateCallParam,\n GetProxyImplementationAddressParam,\n ProxyDataSource,\n} from \"./HttpProxyDataSource\";\nimport { HttpProxyDataSource } from \"./HttpProxyDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpProxyDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n\n let datasource: ProxyDataSource;\n const defaultParams: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 1,\n challenge: \"0x1234567890abcdef\",\n };\n const defaultImplementAddressParams: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 1,\n };\n const delegateProxyResponse: ProxyDelegateCallDto = {\n addresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n };\n const implementationAddressResponse: ProxyImplementationAddress = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n };\n const implementationAddressDto: ProxyImplementationAddressDto = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n standard: \"proxy\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n datasource = new HttpProxyDataSource({\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig);\n });\n\n describe(\"getDelegateProxy\", () => {\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(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should return the delegate proxy response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: delegateProxyResponse,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Right({\n delegateAddresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\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(\"fail\"));\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: { foo: \"bar\" } });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 137, // Polygon\n challenge: \"0x1234567890abcdef\",\n };\n\n // WHEN\n await datasource.getProxyDelegateCall(paramsWithDifferentChainId);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate\",\n }),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n });\n\n describe(\"getImplementAddress\", () => {\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(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should make a GET request to the correct URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n paramsWithDifferentChainId,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should return the implementation address response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: implementationAddressDto,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(Right(implementationAddressResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"network error\"));\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch implementation address\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: { invalid: \"data\" },\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n });\n});\n"],
5
5
  "mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAEP,OAAOC,MAAa,qBASpB,OAAS,uBAAAC,MAA2B,wBAEpC,GAAG,KAAK,OAAO,EAEf,SAAS,sBAAuB,IAAM,CACpC,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,YAAa,aACf,EAEA,IAAIC,EACJ,MAAMC,EAA2C,CAC/C,aAAc,6CACd,SACE,0oCACF,QAAS,EACT,UAAW,oBACb,EACMC,EAAoE,CACxE,aAAc,6CACd,QAAS,CACX,EACMC,EAA8C,CAClD,UAAW,CAAC,4CAA4C,EACxD,iBAAkB,oBACpB,EACMC,EAA4D,CAChE,sBAAuB,4CACzB,EACMC,EAA0D,CAC9D,sBAAuB,6CACvB,aAAc,6CACd,SAAU,OACZ,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjBL,EAAa,IAAIF,EAAoB,CACnC,sBAAuB,CACrB,IAA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CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["axios", "Left", "Right", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "datasource", "defaultParams", "defaultImplementAddressParams", "delegateProxyResponse", "implementationAddressResponse", "implementationAddressDto", "version", "requestSpy", "result", "paramsWithDifferentChainId"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var k=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var C=(n,t,e,r)=>{for(var a=r>1?void 0:r?L(t,e):t,o=n.length-1,c;o>=0;o--)(c=n[o])&&(a=(r?c(t,e,a):c(a))||a);return r&&a&&k(t,e,a),a},s=(n,t)=>(e,r)=>t(e,r,n);import{isHexaString as R}from"@ledgerhq/device-management-kit";import{inject as f,injectable as h}from"inversify";import{pkiTypes as v}from"../../pki/di/pkiTypes";import{KeyId as T}from"../../pki/model/KeyId";import{KeyUsage as A}from"../../pki/model/KeyUsage";import{ClearSignContextType as p}from"../../shared/model/ClearSignContext";import{transactionTypes as g}from"../../transaction/di/transactionTypes";let d=class{constructor(t,e,r){this.transactionDataSource=t;this.proxyDataSource=e;this.certificateLoader=r}async load(t){const{to:e,data:r,selector:a,chainId:o,deviceModelId:c,challenge:y}=t;if(e===void 0||r==="0x")return[];if(!R(a))return[{type:p.ERROR,error:new Error("Invalid selector")}];const u=await this.proxyDataSource.getProxyDelegateCall({calldata:r,proxyAddress:e,chainId:o,challenge:y||""}),[x,l]=u.caseOf({Left:()=>[e,void 0],Right:i=>[i.delegateAddresses.find(P=>P===e)||i.delegateAddresses[0],i.signedDescriptor]});let m;l&&(m=await this.certificateLoader.loadCertificate({keyId:T.CalCalldataKey,keyUsage:A.Calldata,targetDevice:t.deviceModelId}));const D=l?[{type:p.PROXY_DELEGATE_CALL,payload:l,certificate:m}]:[],S=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:c,address:x,chainId:o,selector:a})).caseOf({Left:i=>[{type:p.ERROR,error:i}],Right:i=>i});return[...D,...S]}};d=C([h(),s(0,f(g.TransactionDataSource)),s(1,f(g.ProxyDataSource)),s(2,f(v.PkiCertificateLoader))],d);export{d as TransactionContextLoader};
1
+ var S=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var m=(a,e,r,i)=>{for(var t=i>1?void 0:i?D(e,r):e,o=a.length-1,n;o>=0;o--)(n=a[o])&&(t=(i?n(e,r,t):n(t))||t);return i&&t&&S(e,r,t),t},f=(a,e)=>(r,i)=>e(r,i,a);import{DeviceModelId as x,isHexaString as k}from"@ledgerhq/device-management-kit";import{inject as C,injectable as v}from"inversify";import{pkiTypes as L}from"../../pki/di/pkiTypes";import{KeyId as I}from"../../pki/model/KeyId";import{KeyUsage as P}from"../../pki/model/KeyUsage";import{ClearSignContextType as l}from"../../shared/model/ClearSignContext";import{transactionTypes as R}from"../../transaction/di/transactionTypes";let c=class{constructor(e,r){this.transactionDataSource=e;this.certificateLoader=r}async load(e){if(e.deviceModelId===x.NANO_S)return[];const{to:r,data:i,selector:t,chainId:o,deviceModelId:n}=e;if(r===void 0||i==="0x")return[];if(!k(t))return[{type:l.ERROR,error:new Error("Invalid selector")}];const d=void 0,u=r;let p;d&&(p=await this.certificateLoader.loadCertificate({keyId:I.CalCalldataKey,keyUsage:P.Calldata,targetDevice:e.deviceModelId}));const y=d?[{type:l.PROXY_DELEGATE_CALL,payload:d,certificate:p}]:[],g=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:n,address:u,chainId:o,selector:t})).caseOf({Left:s=>[{type:l.ERROR,error:s}],Right:s=>s});return[...y,...g]}};c=m([v(),f(0,C(R.TransactionDataSource)),f(1,C(L.PkiCertificateLoader))],c);export{c as TransactionContextLoader};
2
2
  //# sourceMappingURL=TransactionContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.ts"],
4
- "sourcesContent": ["import { isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\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 { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { ProxyDataSource } from \"@/transaction/data/HttpProxyDataSource\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\nimport { ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n @inject(transactionTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private certificateLoader: PkiCertificateLoader,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId, challenge } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const proxyDelegateCall = await this.proxyDataSource.getProxyDelegateCall({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: challenge || \"\",\n });\n\n // get the resolved address from the list of delegate addresses\n // if the transaction.to is not in the list of delegate addresses,\n // return the first element as the resolved address,\n // and undefined as the proxy delegate call descriptor\n // if the transaction.to is in the list of delegate addresses,\n // return the transaction.to as the resolved address,\n // and the proxy delegate call descriptor\n const [resolvedAddress, proxyDelegateCallDescriptor]: [\n string,\n string | undefined,\n ] = proxyDelegateCall.caseOf({\n Left: () => [to!, undefined],\n Right: (proxyData: ProxyDelegateCall): [string, string | undefined] => {\n return [\n proxyData.delegateAddresses.find((address) => address === to) ||\n proxyData.delegateAddresses[0]!,\n proxyData.signedDescriptor,\n ];\n },\n });\n\n let certificate: PkiCertificate | undefined = undefined;\n if (proxyDelegateCallDescriptor) {\n certificate = await this.certificateLoader.loadCertificate({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: ctx.deviceModelId,\n });\n }\n\n const proxyDelegateCallContext: ClearSignContext[] =\n proxyDelegateCallDescriptor\n ? [\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: proxyDelegateCallDescriptor,\n certificate: certificate,\n },\n ]\n : [];\n\n const transactionContexts = (\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: resolvedAddress,\n chainId,\n selector,\n })\n ).caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n\n return [...proxyDelegateCallContext, ...transactionContexts];\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,gBAAAA,MAAoB,kCAC7B,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OAEE,wBAAAC,MACK,kCAIP,OAAS,oBAAAC,MAAwB,oCAI1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAEAC,EAEAC,EACR,CALQ,2BAAAF,EAEA,qBAAAC,EAEA,uBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,EAAe,UAAAC,CAAU,EAAIN,EAClE,GAAIC,IAAO,QAAaC,IAAS,KAC/B,MAAO,CAAC,EAGV,GAAI,CAACK,EAAaJ,CAAQ,EACxB,MAAO,CACL,CACE,KAAMK,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,MAAMC,EAAoB,MAAM,KAAK,gBAAgB,qBAAqB,CACxE,SAAUP,EACV,aAAcD,EACd,QAAAG,EACA,UAAWE,GAAa,EAC1B,CAAC,EASK,CAACI,EAAiBC,CAA2B,EAG/CF,EAAkB,OAAO,CAC3B,KAAM,IAAM,CAACR,EAAK,MAAS,EAC3B,MAAQW,GACC,CACLA,EAAU,kBAAkB,KAAMC,GAAYA,IAAYZ,CAAE,GAC1DW,EAAU,kBAAkB,CAAC,EAC/BA,EAAU,gBACZ,CAEJ,CAAC,EAED,IAAIE,EACAH,IACFG,EAAc,MAAM,KAAK,kBAAkB,gBAAgB,CACzD,MAAOC,EAAM,eACb,SAAUC,EAAS,SACnB,aAAchB,EAAI,aACpB,CAAC,GAGH,MAAMiB,EACJN,EACI,CACE,CACE,KAAMH,EAAqB,oBAC3B,QAASG,EACT,YAAaG,CACf,CACF,EACA,CAAC,EAEDI,GACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAb,EACA,QAASK,EACT,QAAAN,EACA,SAAAD,CACF,CAAC,GACD,OAAO,CACP,KAAOgB,GAA8B,CACnC,CACE,KAAMX,EAAqB,MAC3B,MAAAW,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAED,MAAO,CAAC,GAAGH,EAA0B,GAAGC,CAAmB,CAC7D,CACF,EA5FatB,EAANyB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOC,EAAiB,eAAe,GAEvCF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAN5B9B",
6
- "names": ["isHexaString", "inject", "injectable", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "certificateLoader", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "challenge", "isHexaString", "ClearSignContextType", "proxyDelegateCall", "resolvedAddress", "proxyDelegateCallDescriptor", "proxyData", "address", "certificate", "KeyId", "KeyUsage", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "pkiTypes"]
4
+ "sourcesContent": ["import { DeviceModelId, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\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 { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\n//import type { ProxyDataSource } from \"@/transaction/data/HttpProxyDataSource\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n /*@inject(transactionTypes.ProxyDataSource)\n private _proxyDataSource: ProxyDataSource,*/\n @inject(pkiTypes.PkiCertificateLoader)\n private certificateLoader: PkiCertificateLoader,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n //TODO add challenge when proxy is enabled\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n /*\nDISABLE PROXY FOR NOW, to be enabled later\n\n const proxyDelegateCall = await this.proxyDataSource.getProxyDelegateCall({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: challenge || \"\",\n });\n\n // get the resolved address from the list of delegate addresses\n // if the transaction.to is not in the list of delegate addresses,\n // return the first element as the resolved address,\n // and undefined as the proxy delegate call descriptor\n // if the transaction.to is in the list of delegate addresses,\n // return the transaction.to as the resolved address,\n // and the proxy delegate call descriptor\n const [resolvedAddress, proxyDelegateCallDescriptor]: [\n string,\n string | undefined,\n ] = proxyDelegateCall.caseOf({\n Left: () => [to!, undefined],\n Right: (proxyData: ProxyDelegateCall): [string, string | undefined] => {\n return [\n proxyData.delegateAddresses.find((address) => address === to) ||\n proxyData.delegateAddresses[0]!,\n proxyData.signedDescriptor,\n ];\n },\n });\n*/\n // TMP Values to be removed when proxy is enabled\n const proxyDelegateCallDescriptor: string | undefined = undefined;\n const resolvedAddress: string | undefined = to;\n\n let certificate: PkiCertificate | undefined = undefined;\n if (proxyDelegateCallDescriptor) {\n certificate = await this.certificateLoader.loadCertificate({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: ctx.deviceModelId,\n });\n }\n\n const proxyDelegateCallContext: ClearSignContext[] =\n proxyDelegateCallDescriptor\n ? [\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: proxyDelegateCallDescriptor,\n certificate: certificate,\n },\n ]\n : [];\n\n const transactionContexts = (\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: resolvedAddress,\n chainId,\n selector,\n })\n ).caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n\n return [...proxyDelegateCallContext, ...transactionContexts];\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,iBAAAA,EAAe,gBAAAC,MAAoB,kCAC5C,OAAS,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OE,EAAS,oBAAoB,IAN5B1B",
6
+ "names": ["DeviceModelId", "isHexaString", "inject", "injectable", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "certificateLoader", "ctx", "DeviceModelId", "to", "data", "selector", "chainId", "deviceModelId", "isHexaString", "ClearSignContextType", "proxyDelegateCallDescriptor", "resolvedAddress", "certificate", "KeyId", "KeyUsage", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as c,Right as s}from"purify-ts";import{ClearSignContextType as e}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as p}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const r=vi.fn(),n=vi.fn(),d={getTransactionDescriptors:r},l={getProxyDelegateCall:n,getProxyImplementationAddress:vi.fn()},i={loadCertificate:vi.fn()},o=new p(d,l,i);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await o.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await o.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await o.load(a);expect(t).toEqual([{type:e.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{n.mockResolvedValue(c(new Error("data source error"))),r.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:e.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x7","0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x8",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is not in the delegate addresses",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
1
+ import{Left as c,Right as s}from"purify-ts";import{ClearSignContextType as e}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as l}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const r=vi.fn(),n=vi.fn(),d={getTransactionDescriptors:r},i={loadCertificate:vi.fn()},o=new l(d,i);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await o.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await o.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await o.load(a);expect(t).toEqual([{type:e.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{n.mockResolvedValue(c(new Error("data source error"))),r.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:e.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x7","0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x8",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is not in the delegate addresses",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
2
2
  //# sourceMappingURL=TransactionContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type ProxyDataSource } from \"@/transaction/data/HttpProxyDataSource\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const getProxyDelegateCallMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyDelegateCall: getProxyDelegateCallMock,\n getProxyImplementationAddress: vi.fn(),\n };\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n mockProxyDatasource,\n mockCertificateLoader,\n );\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\", \"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x8\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is not in the delegate addresses\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAG5B,OAAS,wBAAAC,MAA4B,kCAIrC,OAAS,4BAAAC,MAAgC,gDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAA2B,GAAG,GAAG,EACjCC,EAAmD,CACvD,0BAA2BF,CAC7B,EACMG,EAAuC,CAC3C,qBAAsBF,EACtB,8BAA+B,GAAG,GAAG,CACvC,EACMG,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAAS,IAAIN,EACjBG,EACAC,EACAC,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,qEAAsE,SAAY,CAEnF,MAAME,EAAc,CAAC,EAGfC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC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,CACH,CAAC,EAED,GAAG,uGAAwG,SAAY,CAErHE,EAA8B,kBAC5BH,EAAM,CACJ,CACE,KAAMC,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACAG,EAAyB,kBACvBJ,EAAM,CACJ,kBAAmB,CAAC,KAAK,EACzB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMS,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMT,EAAqB,oBAC3B,QAAS,oBACX,EACA,CACE,KAAMA,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockProxyDatasource", "mockCertificateLoader", "loader", "transaction", "result"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const getProxyDelegateCallMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n /* const mockProxyDatasource: ProxyDataSource = {\n getProxyDelegateCall: getProxyDelegateCallMock,\n getProxyImplementationAddress: vi.fn(),\n }; */\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n //mockProxyDatasource,\n mockCertificateLoader,\n );\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n /* TODO reenable when proxy is enabled\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },*/\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\", \"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x8\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n /* TODO reenable when proxy is enabled\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },*/\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is not in the delegate addresses\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n /* TODO reenable when proxy is enabled\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },*/\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,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5BH,EAAM,CACJ,CACE,KAAMC,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACAG,EAAyB,kBACvBJ,EAAM,CACJ,kBAAmB,CAAC,MAAO,KAAK,EAChC,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMQ,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAMrB,CACE,KAAMR,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uGAAwG,SAAY,CAErHE,EAA8B,kBAC5BH,EAAM,CACJ,CACE,KAAMC,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACAG,EAAyB,kBACvBJ,EAAM,CACJ,kBAAmB,CAAC,KAAK,EACzB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMQ,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAMrB,CACE,KAAMR,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockCertificateLoader", "loader", "transaction", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var f=(s,r,e,o)=>{for(var t=o>1?void 0:o?$(r,e):r,n=s.length-1,a;n>=0;n--)(a=s[n])&&(t=(o?a(r,e,t):a(t))||t);return o&&t&&T(r,e,t),t},l=(s,r)=>(e,o)=>r(e,o,s);import p from"axios";import{inject as y,injectable as C}from"inversify";import{Left as m,Right as c}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as h,LEDGER_ORIGIN_TOKEN_HEADER as E}from"../../shared/constant/HttpHeaders";import D from"../../../package.json";let d=class{constructor(r){this.config=r}async getDomainNamePayload({chainId:r,domain:e,challenge:o}){try{const a=await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/names/ethereum/${r}/forward/${e}?types=eoa&sources=ens&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}});return a.data.signedDescriptor?.data?c(a.data.signedDescriptor.data):m(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:r,address:e,challenge:o,sources:t,types:n}){try{t=t.filter(g=>g==="ens"||g==="crypto_asset_list");const i=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/names/ethereum/${r}/reverse/${e}?types=${n.join(",")}&sources=${t.join(",")}&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}})).data;if(!i?.signedDescriptor?.data)return m(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${e}`));const u=i.signedDescriptor.data;if(!i.signedDescriptor.signatures||typeof i.signedDescriptor.signatures[this.config.cal.mode]!="string")return c(u);const N=i.signedDescriptor.signatures[this.config.cal.mode];return c(this.formatTrustedName(u,N))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(r,e){e.length%2!==0&&(e="0"+e);const o="15",t=(e.length/2).toString(16);return`${r}${o}${t}${e}`}};d=f([C(),l(0,y(x.Config))],d);export{d as HttpTrustedNameDataSource};
1
+ var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var f=(s,r,e,o)=>{for(var t=o>1?void 0:o?$(r,e):r,n=s.length-1,a;n>=0;n--)(a=s[n])&&(t=(o?a(r,e,t):a(t))||t);return o&&t&&T(r,e,t),t},l=(s,r)=>(e,o)=>r(e,o,s);import p from"axios";import{inject as y,injectable as C}from"inversify";import{Left as m,Right as c}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as h,LEDGER_ORIGIN_TOKEN_HEADER as E}from"../../shared/constant/HttpHeaders";import D from"../../../package.json";let d=class{constructor(r){this.config=r}async getDomainNamePayload({chainId:r,domain:e,challenge:o}){try{const a=await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/names/ethereum/${r}/forward/${e}?types=eoa&sources=ens&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}});return a.data.signedDescriptor?.data?c(a.data.signedDescriptor.data):m(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:r,address:e,challenge:o,sources:t,types:n}){try{t=t.filter(g=>g==="ens"||g==="crypto_asset_list");const i=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/names/ethereum/${r}/reverse/${e}?types=${n.join(",")}&sources=${t.join(",")}&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}})).data;if(!i?.signedDescriptor?.data)return m(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${e}`));const u=i.signedDescriptor.data;if(!i.signedDescriptor.signatures||typeof i.signedDescriptor.signatures[this.config.cal.mode]!="string")return c(u);const N=i.signedDescriptor.signatures[this.config.cal.mode];return c(this.formatTrustedName(u,N))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(r,e){e.length%2!==0&&(e="0"+e);const o="15",t=(e.length/2).toString(16);return`${r}${o}${t}${e}`}};d=f([C(),l(0,y(x.Config))],d);export{d as HttpTrustedNameDataSource};
2
2
  //# sourceMappingURL=HttpTrustedNameDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/data/HttpTrustedNameDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n GetDomainNameInfosParams,\n GetTrustedNameInfosParams,\n TrustedNameDataSource,\n} from \"@/trusted-name/data/TrustedNameDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { TrustedNameDto } from \"./TrustedNameDto\";\n\n@injectable()\nexport class HttpTrustedNameDataSource implements TrustedNameDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getDomainNamePayload({\n chainId,\n domain,\n challenge,\n }: GetDomainNameInfosParams): Promise<Either<Error, string>> {\n try {\n const type = \"eoa\"; // Externally owned account\n const source = \"ens\"; // Ethereum name service\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/names/ethereum/${chainId}/forward/${domain}?types=${type}&sources=${source}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.signedDescriptor?.data\n ? Right(response.data.signedDescriptor.data)\n : Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: error getting domain payload\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name\",\n ),\n );\n }\n }\n\n public async getTrustedNamePayload({\n chainId,\n address,\n challenge,\n sources,\n types,\n }: GetTrustedNameInfosParams): Promise<Either<Error, string>> {\n try {\n // TODO remove that filtering once https://ledgerhq.atlassian.net/browse/BACK-8075 is done\n // For now we have to filter or trusted names won't work with the generic parser, because transaction\n // fields descriptors can contain unsupported sources.\n sources = sources.filter(\n (source) => source === \"ens\" || source === \"crypto_asset_list\",\n );\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/names/ethereum/${chainId}/reverse/${address}?types=${types.join(\",\")}&sources=${sources.join(\",\")}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n const trustedName = response.data;\n if (!trustedName?.signedDescriptor?.data) {\n return Left(\n new Error(\n `[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${address}`,\n ),\n );\n }\n const payload = trustedName.signedDescriptor.data;\n\n if (\n !trustedName.signedDescriptor.signatures ||\n typeof trustedName.signedDescriptor.signatures[this.config.cal.mode] !==\n \"string\"\n ) {\n // If we have no separated signature but a valid descriptor, it may mean the descriptor was\n // signed on-the-fly for dynamic sources such as ens\n return Right(payload);\n }\n\n const signature =\n trustedName.signedDescriptor.signatures[this.config.cal.mode]!;\n return Right(this.formatTrustedName(payload, signature));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name\",\n ),\n );\n }\n }\n\n private formatTrustedName(payload: string, signature: string): string {\n // Ensure correct padding\n if (signature.length % 2 !== 0) {\n signature = \"0\" + signature;\n }\n // TLV encoding as according to trusted name documentation\n const signatureTag = \"15\";\n const signatureLength = (signature.length / 2).toString(16);\n return `${payload}${signatureTag}${signatureLength}${signature}`;\n }\n}\n"],
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n GetDomainNameInfosParams,\n GetTrustedNameInfosParams,\n TrustedNameDataSource,\n} from \"@/trusted-name/data/TrustedNameDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { TrustedNameDto } from \"./TrustedNameDto\";\n\n@injectable()\nexport class HttpTrustedNameDataSource implements TrustedNameDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getDomainNamePayload({\n chainId,\n domain,\n challenge,\n }: GetDomainNameInfosParams): Promise<Either<Error, string>> {\n try {\n const type = \"eoa\"; // Externally owned account\n const source = \"ens\"; // Ethereum name service\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/names/ethereum/${chainId}/forward/${domain}?types=${type}&sources=${source}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.signedDescriptor?.data\n ? Right(response.data.signedDescriptor.data)\n : Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: error getting domain payload\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name\",\n ),\n );\n }\n }\n\n public async getTrustedNamePayload({\n chainId,\n address,\n challenge,\n sources,\n types,\n }: GetTrustedNameInfosParams): Promise<Either<Error, string>> {\n try {\n // TODO remove that filtering once https://ledgerhq.atlassian.net/browse/BACK-8075 is done\n // For now we have to filter or trusted names won't work with the generic parser, because transaction\n // fields descriptors can contain unsupported sources.\n sources = sources.filter(\n (source) => source === \"ens\" || source === \"crypto_asset_list\",\n );\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/names/ethereum/${chainId}/reverse/${address}?types=${types.join(\",\")}&sources=${sources.join(\",\")}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n const trustedName = response.data;\n if (!trustedName?.signedDescriptor?.data) {\n return Left(\n new Error(\n `[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${address}`,\n ),\n );\n }\n const payload = trustedName.signedDescriptor.data;\n\n if (\n !trustedName.signedDescriptor.signatures ||\n typeof trustedName.signedDescriptor.signatures[this.config.cal.mode] !==\n \"string\"\n ) {\n // If we have no separated signature but a valid descriptor, it may mean the descriptor was\n // signed on-the-fly for dynamic sources such as ens\n return Right(payload);\n }\n\n const signature =\n trustedName.signedDescriptor.signatures[this.config.cal.mode]!;\n return Right(this.formatTrustedName(payload, signature));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name\",\n ),\n );\n }\n }\n\n private formatTrustedName(payload: string, signature: string): string {\n // Ensure correct padding\n if (signature.length % 2 !== 0) {\n signature = \"0\" + signature;\n }\n // TLV encoding as according to trusted name documentation\n const signatureTag = \"15\";\n const signatureLength = (signature.length / 2).toString(16);\n return `${payload}${signatureTag}${signatureLength}${signature}`;\n }\n}\n"],
5
5
  "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAMP,OAAOC,MAAa,qBAKb,IAAMC,EAAN,KAA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,WAAW,KAAK,OAAO,IAAI,IAAI,GACjE,SAIF,OAAON,EAAMO,CAAO,EAGtB,MAAMC,EACJF,EAAY,iBAAiB,WAAW,KAAK,OAAO,IAAI,IAAI,EAC9D,OAAON,EAAM,KAAK,kBAAkBO,EAASC,CAAS,CAAC,CACzD,MAAiB,CACf,OAAOP,EACL,IAAI,MACF,yEACF,CACF,CACF,CACF,CAEQ,kBAAkBM,EAAiBC,EAA2B,CAEhEA,EAAU,OAAS,IAAM,IAC3BA,EAAY,IAAMA,GAGpB,MAAMC,EAAe,KACfC,GAAmBF,EAAU,OAAS,GAAG,SAAS,EAAE,EAC1D,MAAO,GAAGD,CAAO,GAAGE,CAAY,GAAGC,CAAe,GAAGF,CAAS,EAChE,CACF,EAtGalB,EAANqB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBzB",
6
6
  "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpTrustedNameDataSource", "config", "chainId", "domain", "challenge", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Right", "Left", "address", "sources", "types", "source", "trustedName", "payload", "signature", "signatureTag", "signatureLength", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import o from"axios";import{Left as r,Right as s}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as l,LEDGER_ORIGIN_TOKEN_HEADER as d}from"../../shared/constant/HttpHeaders";import{HttpTrustedNameDataSource as c}from"../../trusted-name/data/HttpTrustedNameDataSource";import i from"../../../package.json";vi.mock("axios");const n={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"},metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"};describe("HttpTrustedNameDataSource",()=>{let t;beforeAll(()=>{t=new c(n),vi.clearAllMocks()}),describe("getDomainNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getDomainNamePayload({chainId:137,challenge:"9876",domain:"hello.eth"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v1/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"challenge",domain:"hello.eth"});expect(a).toEqual(s("payload"))})}),describe("getTrustedNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"5678",sources:["ens","crypto_asset_list"],types:["eoa"]}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v1/names/ethereum/137/reverse/0x1234?types=eoa&sources=ens,crypto_asset_list&challenge=5678",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address 0x1234")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload"))}),it("should return a payload with a signature",async()=>{const e={data:{signedDescriptor:{data:"payload",signatures:{prod:"12345"}}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload153012345"))})})});
1
+ import o from"axios";import{Left as r,Right as s}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as l,LEDGER_ORIGIN_TOKEN_HEADER as d}from"../../shared/constant/HttpHeaders";import{HttpTrustedNameDataSource as c}from"../../trusted-name/data/HttpTrustedNameDataSource";import i from"../../../package.json";vi.mock("axios");const n={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"},metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"};describe("HttpTrustedNameDataSource",()=>{let t;beforeAll(()=>{t=new c(n),vi.clearAllMocks()}),describe("getDomainNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getDomainNamePayload({chainId:137,challenge:"9876",domain:"hello.eth"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v2/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"challenge",domain:"hello.eth"});expect(a).toEqual(s("payload"))})}),describe("getTrustedNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"5678",sources:["ens","crypto_asset_list"],types:["eoa"]}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v2/names/ethereum/137/reverse/0x1234?types=eoa&sources=ens,crypto_asset_list&challenge=5678",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address 0x1234")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload"))}),it("should return a payload with a signature",async()=>{const e={data:{signedDescriptor:{data:"payload",signatures:{prod:"12345"}}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload153012345"))})})});
2
2
  //# sourceMappingURL=HttpTrustedNameDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/data/HttpTrustedNameDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { HttpTrustedNameDataSource } from \"@/trusted-name/data/HttpTrustedNameDataSource\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nconst config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpTrustedNameDataSource\", () => {\n let datasource: TrustedNameDataSource;\n\n beforeAll(() => {\n datasource = new HttpTrustedNameDataSource(config);\n vi.clearAllMocks();\n });\n\n describe(\"getDomainNamePayload\", () => {\n it(\"should call axios with the correct url and 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.getDomainNamePayload({\n chainId: 137,\n challenge: \"9876\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n url: `https://nft.api.live.ledger.com/v1/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should throw 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.getDomainNamePayload({\n chainId: 137,\n challenge: \"\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name\",\n ),\n ),\n );\n });\n\n it(\"should return an error when no payload is returned\", async () => {\n // GIVEN\n const response = { data: { test: \"\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getDomainNamePayload({\n chainId: 137,\n challenge: \"\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: error getting domain payload\",\n ),\n ),\n );\n });\n\n it(\"should return a payload\", async () => {\n // GIVEN\n const response = { data: { signedDescriptor: { data: \"payload\" } } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getDomainNamePayload({\n chainId: 137,\n challenge: \"challenge\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(result).toEqual(Right(\"payload\"));\n });\n });\n\n describe(\"getTrustedNamePayload\", () => {\n it(\"should call axios with the correct url and 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.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"5678\",\n sources: [\"ens\", \"crypto_asset_list\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n url: `https://nft.api.live.ledger.com/v1/names/ethereum/137/reverse/0x1234?types=eoa&sources=ens,crypto_asset_list&challenge=5678`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should throw 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.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name\",\n ),\n ),\n );\n });\n\n it(\"should return an error when no payload is returned\", async () => {\n // GIVEN\n const response = { data: { test: \"\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address 0x1234\",\n ),\n ),\n );\n });\n\n it(\"should return a payload\", async () => {\n // GIVEN\n const response = {\n data: {\n signedDescriptor: { data: \"payload\" },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(Right(\"payload\"));\n });\n\n it(\"should return a payload with a signature\", async () => {\n // GIVEN\n const response = {\n data: {\n signedDescriptor: { data: \"payload\", signatures: { prod: \"12345\" } },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(Right(\"payload153012345\"));\n });\n });\n});\n"],
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { HttpTrustedNameDataSource } from \"@/trusted-name/data/HttpTrustedNameDataSource\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nconst config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpTrustedNameDataSource\", () => {\n let datasource: TrustedNameDataSource;\n\n beforeAll(() => {\n datasource = new HttpTrustedNameDataSource(config);\n vi.clearAllMocks();\n });\n\n describe(\"getDomainNamePayload\", () => {\n it(\"should call axios with the correct url and 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.getDomainNamePayload({\n chainId: 137,\n challenge: \"9876\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n url: `https://nft.api.live.ledger.com/v2/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should throw 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.getDomainNamePayload({\n chainId: 137,\n challenge: \"\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name\",\n ),\n ),\n );\n });\n\n it(\"should return an error when no payload is returned\", async () => {\n // GIVEN\n const response = { data: { test: \"\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getDomainNamePayload({\n chainId: 137,\n challenge: \"\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: error getting domain payload\",\n ),\n ),\n );\n });\n\n it(\"should return a payload\", async () => {\n // GIVEN\n const response = { data: { signedDescriptor: { data: \"payload\" } } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getDomainNamePayload({\n chainId: 137,\n challenge: \"challenge\",\n domain: \"hello.eth\",\n });\n\n // THEN\n expect(result).toEqual(Right(\"payload\"));\n });\n });\n\n describe(\"getTrustedNamePayload\", () => {\n it(\"should call axios with the correct url and 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.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"5678\",\n sources: [\"ens\", \"crypto_asset_list\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n url: `https://nft.api.live.ledger.com/v2/names/ethereum/137/reverse/0x1234?types=eoa&sources=ens,crypto_asset_list&challenge=5678`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should throw 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.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name\",\n ),\n ),\n );\n });\n\n it(\"should return an error when no payload is returned\", async () => {\n // GIVEN\n const response = { data: { test: \"\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address 0x1234\",\n ),\n ),\n );\n });\n\n it(\"should return a payload\", async () => {\n // GIVEN\n const response = {\n data: {\n signedDescriptor: { data: \"payload\" },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(Right(\"payload\"));\n });\n\n it(\"should return a payload with a signature\", async () => {\n // GIVEN\n const response = {\n data: {\n signedDescriptor: { data: \"payload\", signatures: { prod: \"12345\" } },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getTrustedNamePayload({\n chainId: 137,\n address: \"0x1234\",\n challenge: \"\",\n sources: [\"ens\"],\n types: [\"eoa\"],\n });\n\n // THEN\n expect(result).toEqual(Right(\"payload153012345\"));\n });\n });\n});\n"],
5
5
  "mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAS,6BAAAC,MAAiC,gDAE1C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAS,CACb,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,EACA,sBAAuB,CACrB,IAAK,iCACP,EACA,YAAa,aACf,EACA,SAAS,4BAA6B,IAAM,CAC1C,IAAIC,EAEJ,UAAU,IAAM,CACdA,EAAa,IAAIH,EAA0BE,CAAM,EACjD,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,uBAAwB,IAAM,CACrC,GAAG,0EAA2E,SAAY,CAExF,MAAME,EAAU,kBAAkBH,EAAQ,OAAO,GAC3CI,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAMV,EAAO,SAAS,EAAE,mBAAmBU,CAAU,EAGxD,MAAMF,EAAW,qBAAqB,CACpC,QAAS,IACT,UAAW,OACX,OAAQ,WACV,CAAC,EAGD,OAAOE,CAAU,EAAE,qBACjB,OAAO,iBAAiB,CACtB,IAAK,+GACL,QAAS,CACP,CAACP,CAA4B,EAAGM,EAChC,CAACL,CAA0B,EAAGG,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,EAED,GAAG,mDAAoD,SAAY,CAEjE,GAAG,MAAMP,EAAO,SAAS,EAAE,kBAAkB,IAAI,KAAO,EAGxD,MAAMW,EAAS,MAAMH,EAAW,qBAAqB,C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ACpD,QAAS,IACT,QAAS,SACT,UAAW,GACX,QAAS,CAAC,KAAK,EACf,MAAO,CAAC,KAAK,CACf,CAAC,EAGD,OAAOG,CAAM,EAAE,QAAQT,EAAM,kBAAkB,CAAC,CAClD,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["axios", "Left", "Right", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "HttpTrustedNameDataSource", "PACKAGE", "config", "datasource", "version", "requestSpy", "result", "response"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultPkiCertificateLoader.d.ts","sourceRoot":"","sources":["../../../../../src/pki/domain/DefaultPkiCertificateLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAEpF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,qBACa,2BAA4B,YAAW,oBAAoB;IACtE,OAAO,CAAC,WAAW,CAA2B;gBAI5C,UAAU,EAAE,wBAAwB;IAKhC,eAAe,CACnB,gBAAgB,EAAE,kBAAkB,GACnC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;CAWvC"}
1
+ {"version":3,"file":"DefaultPkiCertificateLoader.d.ts","sourceRoot":"","sources":["../../../../../src/pki/domain/DefaultPkiCertificateLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAEpF,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,qBACa,2BAA4B,YAAW,oBAAoB;IACtE,OAAO,CAAC,WAAW,CAA2B;gBAI5C,UAAU,EAAE,wBAAwB;IAKhC,eAAe,CACnB,gBAAgB,EAAE,kBAAkB,GACnC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;CAOvC"}
@@ -2,13 +2,11 @@ import type { PkiCertificateLoader } from "../../pki/domain/PkiCertificateLoader
2
2
  import { ContextLoader } from "../../shared/domain/ContextLoader";
3
3
  import { ClearSignContext } from "../../shared/model/ClearSignContext";
4
4
  import { TransactionContext } from "../../shared/model/TransactionContext";
5
- import type { ProxyDataSource } from "../../transaction/data/HttpProxyDataSource";
6
5
  import type { TransactionDataSource } from "../../transaction/data/TransactionDataSource";
7
6
  export declare class TransactionContextLoader implements ContextLoader {
8
7
  private transactionDataSource;
9
- private proxyDataSource;
10
8
  private certificateLoader;
11
- constructor(transactionDataSource: TransactionDataSource, proxyDataSource: ProxyDataSource, certificateLoader: PkiCertificateLoader);
9
+ constructor(transactionDataSource: TransactionDataSource, certificateLoader: PkiCertificateLoader);
12
10
  load(ctx: TransactionContext): Promise<ClearSignContext[]>;
13
11
  }
14
12
  //# sourceMappingURL=TransactionContextLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionContextLoader.d.ts","sourceRoot":"","sources":["../../../../../src/transaction/domain/TransactionContextLoader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAI9E,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAItF,qBACa,wBAAyB,YAAW,aAAa;IAG1D,OAAO,CAAC,qBAAq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