@ledgerhq/context-module 0.0.0-multisig-20250910160951 → 0.0.0-multisig-20250918154034

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 (187) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModule.js +1 -1
  3. package/lib/cjs/src/ContextModule.js.map +1 -1
  4. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  6. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  7. package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
  8. package/lib/cjs/src/DefaultContextModule.js +1 -1
  9. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  10. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  11. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  12. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  13. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  14. package/lib/cjs/src/di.js +1 -1
  15. package/lib/cjs/src/di.js.map +2 -2
  16. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  17. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +2 -2
  18. package/lib/cjs/src/index.js +1 -1
  19. package/lib/cjs/src/index.js.map +2 -2
  20. package/lib/cjs/src/nft/domain/NftContextFieldLoader.js +1 -1
  21. package/lib/cjs/src/nft/domain/NftContextFieldLoader.js.map +2 -2
  22. package/lib/cjs/src/nft/domain/NftContextFieldLoader.test.js +1 -1
  23. package/lib/cjs/src/nft/domain/NftContextFieldLoader.test.js.map +3 -3
  24. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js +1 -1
  25. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  26. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  27. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  28. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js +2 -0
  29. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js.map +7 -0
  30. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js +2 -0
  31. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js.map +7 -0
  32. package/lib/cjs/src/proxy/data/ProxyDataSource.js +2 -0
  33. package/lib/cjs/src/proxy/data/ProxyDataSource.js.map +7 -0
  34. package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +2 -0
  35. package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js.map +7 -0
  36. package/lib/cjs/src/proxy/di/proxyModuleFactory.js +1 -1
  37. package/lib/cjs/src/proxy/di/proxyModuleFactory.js.map +3 -3
  38. package/lib/cjs/src/proxy/di/proxyModuleFactory.test.js +2 -0
  39. package/lib/cjs/src/proxy/di/proxyModuleFactory.test.js.map +7 -0
  40. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
  41. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js.map +2 -2
  42. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
  43. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js.map +3 -3
  44. package/lib/cjs/src/proxy/model/ProxyDelegateCall.js +1 -1
  45. package/lib/cjs/src/proxy/model/ProxyDelegateCall.js.map +1 -1
  46. package/lib/cjs/src/shared/domain/ContextFieldLoader.js +1 -1
  47. package/lib/cjs/src/shared/domain/ContextFieldLoader.js.map +2 -2
  48. package/lib/cjs/src/shared/domain/ContextLoader.js +1 -1
  49. package/lib/cjs/src/shared/domain/ContextLoader.js.map +1 -1
  50. package/lib/cjs/src/shared/model/TypedDataClearSignContext.js.map +1 -1
  51. package/lib/cjs/src/shared/model/TypedDataContext.js.map +1 -1
  52. package/lib/cjs/src/token/domain/TokenContextFieldLoader.js +1 -1
  53. package/lib/cjs/src/token/domain/TokenContextFieldLoader.js.map +3 -3
  54. package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js +1 -1
  55. package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js.map +3 -3
  56. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +1 -1
  57. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +2 -2
  58. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  59. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  60. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  61. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  62. package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.js +1 -1
  63. package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.js.map +2 -2
  64. package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js +1 -1
  65. package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js.map +3 -3
  66. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  67. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +1 -1
  68. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  69. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  70. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  71. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
  72. package/lib/esm/package.json +1 -1
  73. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  74. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  75. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  76. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  77. package/lib/esm/src/DefaultContextModule.js +1 -1
  78. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  79. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  80. package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
  81. package/lib/esm/src/di.js +1 -1
  82. package/lib/esm/src/di.js.map +2 -2
  83. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  84. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +2 -2
  85. package/lib/esm/src/index.js +1 -1
  86. package/lib/esm/src/index.js.map +2 -2
  87. package/lib/esm/src/nft/domain/NftContextFieldLoader.js +1 -1
  88. package/lib/esm/src/nft/domain/NftContextFieldLoader.js.map +3 -3
  89. package/lib/esm/src/nft/domain/NftContextFieldLoader.test.js +1 -1
  90. package/lib/esm/src/nft/domain/NftContextFieldLoader.test.js.map +3 -3
  91. package/lib/esm/src/proxy/data/HttpProxyDataSource.js +1 -1
  92. package/lib/esm/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  93. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  94. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  95. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js +2 -0
  96. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js.map +7 -0
  97. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js +2 -0
  98. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js.map +7 -0
  99. package/lib/esm/src/proxy/data/ProxyDataSource.js +1 -0
  100. package/lib/esm/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +1 -0
  101. package/lib/esm/src/proxy/data/dto/SafeProxyImplementationAddressDto.js.map +7 -0
  102. package/lib/esm/src/proxy/di/proxyModuleFactory.js +1 -1
  103. package/lib/esm/src/proxy/di/proxyModuleFactory.js.map +3 -3
  104. package/lib/esm/src/proxy/di/proxyModuleFactory.test.js +2 -0
  105. package/lib/esm/src/proxy/di/proxyModuleFactory.test.js.map +7 -0
  106. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
  107. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
  108. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
  109. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js.map +3 -3
  110. package/lib/esm/src/shared/domain/ContextFieldLoader.js +1 -1
  111. package/lib/esm/src/shared/domain/ContextFieldLoader.js.map +2 -2
  112. package/lib/esm/src/shared/model/TypedDataClearSignContext.js.map +1 -1
  113. package/lib/esm/src/token/domain/TokenContextFieldLoader.js +1 -1
  114. package/lib/esm/src/token/domain/TokenContextFieldLoader.js.map +3 -3
  115. package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js +1 -1
  116. package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js.map +3 -3
  117. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +1 -1
  118. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +2 -2
  119. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  120. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  121. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  122. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  123. package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.js +1 -1
  124. package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.js.map +3 -3
  125. package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js +1 -1
  126. package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js.map +3 -3
  127. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  128. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +1 -1
  129. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  130. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  131. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  132. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
  133. package/lib/types/src/ContextModule.d.ts +1 -3
  134. package/lib/types/src/ContextModule.d.ts.map +1 -1
  135. package/lib/types/src/ContextModuleBuilder.d.ts +8 -1
  136. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  137. package/lib/types/src/DefaultContextModule.d.ts +2 -3
  138. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  139. package/lib/types/src/config/model/ContextModuleConfig.d.ts +7 -0
  140. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  141. package/lib/types/src/index.d.ts +38 -0
  142. package/lib/types/src/index.d.ts.map +1 -1
  143. package/lib/types/src/nft/domain/NftContextFieldLoader.d.ts +9 -4
  144. package/lib/types/src/nft/domain/NftContextFieldLoader.d.ts.map +1 -1
  145. package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts +2 -22
  146. package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts.map +1 -1
  147. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts +13 -0
  148. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts.map +1 -0
  149. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.test.d.ts +2 -0
  150. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.test.d.ts.map +1 -0
  151. package/lib/types/src/proxy/data/ProxyDataSource.d.ts +15 -0
  152. package/lib/types/src/proxy/data/ProxyDataSource.d.ts.map +1 -0
  153. package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts +8 -0
  154. package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts.map +1 -0
  155. package/lib/types/src/proxy/di/proxyModuleFactory.d.ts +2 -1
  156. package/lib/types/src/proxy/di/proxyModuleFactory.d.ts.map +1 -1
  157. package/lib/types/src/proxy/di/proxyModuleFactory.test.d.ts +2 -0
  158. package/lib/types/src/proxy/di/proxyModuleFactory.test.d.ts.map +1 -0
  159. package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts +14 -5
  160. package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts.map +1 -1
  161. package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts +1 -1
  162. package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts.map +1 -1
  163. package/lib/types/src/shared/domain/ContextFieldLoader.d.ts +3 -4
  164. package/lib/types/src/shared/domain/ContextFieldLoader.d.ts.map +1 -1
  165. package/lib/types/src/shared/domain/ContextLoader.d.ts +0 -2
  166. package/lib/types/src/shared/domain/ContextLoader.d.ts.map +1 -1
  167. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts +1 -1
  168. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts.map +1 -1
  169. package/lib/types/src/shared/model/TypedDataContext.d.ts +1 -1
  170. package/lib/types/src/shared/model/TypedDataContext.d.ts.map +1 -1
  171. package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts +8 -4
  172. package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts.map +1 -1
  173. package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +1 -1
  174. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +1 -1
  175. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  176. package/lib/types/src/trusted-name/domain/TrustedNameContextFieldLoader.d.ts +12 -4
  177. package/lib/types/src/trusted-name/domain/TrustedNameContextFieldLoader.d.ts.map +1 -1
  178. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts +1 -1
  179. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  180. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  181. package/package.json +5 -5
  182. package/lib/cjs/src/proxy/model/ProxyImplementationAddress.js +0 -2
  183. package/lib/cjs/src/proxy/model/ProxyImplementationAddress.js.map +0 -7
  184. package/lib/esm/src/proxy/model/ProxyImplementationAddress.js +0 -1
  185. package/lib/types/src/proxy/model/ProxyImplementationAddress.d.ts +0 -4
  186. package/lib/types/src/proxy/model/ProxyImplementationAddress.d.ts.map +0 -1
  187. /package/lib/esm/src/proxy/{model/ProxyImplementationAddress.js.map → data/ProxyDataSource.js.map} +0 -0
@@ -1,2 +1,2 @@
1
- import{Left as l,Right as s}from"purify-ts";import{ContextFieldLoaderKind as i}from"../../shared/domain/ContextFieldLoader";import{ClearSignContextType as d}from"../../shared/model/ClearSignContext";import{TokenContextFieldLoader as c}from"../../token/domain/TokenContextFieldLoader";describe("TokenContextFieldLoader",()=>{const o={getTokenInfosPayload:vi.fn()},n=new c(o),t={kind:i.TOKEN,chainId:1,address:"0x1234567890abcdef"},r="0x123456789abcdef0";beforeEach(()=>{vi.resetAllMocks()}),describe("constructor",()=>{it("should initialize with correct kind",()=>{expect(n.kind).toBe(i.TOKEN)})}),describe("loadField",()=>{it("should return error context when token data source fails",async()=>{const e=new Error("Token data source error");vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(l(e));const a=await n.loadField(t);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:t.address,chainId:t.chainId}),expect(a).toEqual({type:d.ERROR,error:e})}),it("should return token context when successful",async()=>{vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(s(r));const e=await n.loadField(t);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:t.address,chainId:t.chainId}),expect(e).toEqual({type:d.TOKEN,payload:r})}),it("should handle different chain IDs and addresses correctly",async()=>{const e={...t,chainId:137,address:"0xdeadbeef"};vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(s(r));const a=await n.loadField(e);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:"0xdeadbeef",chainId:137}),expect(a).toEqual({type:d.TOKEN,payload:r})}),it("should preserve error message from token data source",async()=>{const e=new Error("Network timeout error");vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(l(e));const a=await n.loadField(t);expect(a).toEqual({type:d.ERROR,error:e})}),it("should handle empty token payload",async()=>{const e="";vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(s(e));const a=await n.loadField(t);expect(a).toEqual({type:d.TOKEN,payload:e})})})});
1
+ import{Left as i,Right as r}from"purify-ts";import{ContextFieldLoaderKind as d}from"../../shared/domain/ContextFieldLoader";import{ClearSignContextType as s}from"../../shared/model/ClearSignContext";import{TokenContextFieldLoader as c}from"../../token/domain/TokenContextFieldLoader";describe("TokenContextFieldLoader",()=>{const a={getTokenInfosPayload:vi.fn()},t=new c(a),o={kind:d.TOKEN,chainId:1,address:"0x1234567890abcdef"},l="0x123456789abcdef0";beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle",()=>{it("should return true for valid token field",()=>{const e={kind:d.TOKEN,chainId:1,address:"0x1234567890abcdef"};expect(t.canHandle(e)).toBe(!0)}),describe("should return false for invalid fields",()=>{const e=[{name:"null",value:null},{name:"undefined",value:void 0},{name:"string",value:"invalid"},{name:"number",value:123},{name:"boolean",value:!0},{name:"array",value:[]},{name:"empty object",value:{}},{name:"object missing kind",value:{chainId:1,address:"0x123"}},{name:"object missing chainId",value:{kind:d.TOKEN,address:"0x123"}},{name:"object missing address",value:{kind:d.TOKEN,chainId:1}},{name:"object with wrong kind",value:{kind:d.NFT,chainId:1,address:"0x123"}}];test.each(e)("$name",({value:n})=>{expect(t.canHandle(n)).toBe(!1)})})}),describe("loadField",()=>{it("should return error context when token data source fails",async()=>{const e=new Error("Token data source error");vi.spyOn(a,"getTokenInfosPayload").mockResolvedValue(i(e));const n=await t.loadField(o);expect(a.getTokenInfosPayload).toHaveBeenCalledWith({address:o.address,chainId:o.chainId}),expect(n).toEqual({type:s.ERROR,error:e})}),it("should return token context when successful",async()=>{vi.spyOn(a,"getTokenInfosPayload").mockResolvedValue(r(l));const e=await t.loadField(o);expect(a.getTokenInfosPayload).toHaveBeenCalledWith({address:o.address,chainId:o.chainId}),expect(e).toEqual({type:s.TOKEN,payload:l})}),it("should handle different chain IDs and addresses correctly",async()=>{const e={...o,chainId:137,address:"0xdeadbeef"};vi.spyOn(a,"getTokenInfosPayload").mockResolvedValue(r(l));const n=await t.loadField(e);expect(a.getTokenInfosPayload).toHaveBeenCalledWith({address:"0xdeadbeef",chainId:137}),expect(n).toEqual({type:s.TOKEN,payload:l})}),it("should preserve error message from token data source",async()=>{const e=new Error("Network timeout error");vi.spyOn(a,"getTokenInfosPayload").mockResolvedValue(i(e));const n=await t.loadField(o);expect(n).toEqual({type:s.ERROR,error:e})}),it("should handle empty token payload",async()=>{const e="";vi.spyOn(a,"getTokenInfosPayload").mockResolvedValue(r(e));const n=await t.loadField(o);expect(n).toEqual({type:s.TOKEN,payload:e})})})});
2
2
  //# sourceMappingURL=TokenContextFieldLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/domain/TokenContextFieldLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ContextFieldLoaderKind } from \"@/shared/domain/ContextFieldLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionFieldContext } from \"@/shared/model/TransactionFieldContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextFieldLoader } from \"@/token/domain/TokenContextFieldLoader\";\n\ndescribe(\"TokenContextFieldLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const tokenContextFieldLoader = new TokenContextFieldLoader(\n mockTokenDataSource,\n );\n\n const mockTransactionField: TransactionFieldContext<ContextFieldLoaderKind.TOKEN> =\n {\n kind: ContextFieldLoaderKind.TOKEN,\n chainId: 1,\n address: \"0x1234567890abcdef\",\n };\n\n const mockTokenPayload = \"0x123456789abcdef0\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"constructor\", () => {\n it(\"should initialize with correct kind\", () => {\n // THEN\n expect(tokenContextFieldLoader.kind).toBe(ContextFieldLoaderKind.TOKEN);\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when token data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Token data source error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n });\n\n it(\"should return token context when successful\", async () => {\n // GIVEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should handle different chain IDs and addresses correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n chainId: 137,\n address: \"0xdeadbeef\",\n };\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result = await tokenContextFieldLoader.loadField(customField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: \"0xdeadbeef\",\n chainId: 137,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should preserve error message from token data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(specificError),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty token payload\", async () => {\n // GIVEN\n const emptyPayload = \"\";\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(emptyPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: emptyPayload,\n });\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,0BAAAC,MAA8B,qCACvC,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,2BAAAC,MAA+B,yCAExC,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAA0B,IAAIF,EAClCC,CACF,EAEME,EACJ,CACE,KAAML,EAAuB,MAC7B,QAAS,EACT,QAAS,oBACX,EAEIM,EAAmB,qBAEzB,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,cAAe,IAAM,CAC5B,GAAG,sCAAuC,IAAM,CAE9C,OAAOF,EAAwB,IAAI,EAAE,KAAKJ,EAAuB,KAAK,CACxE,CAAC,CACH,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,GAAG,2DAA4D,SAAY,CAEzE,MAAMO,EAAQ,IAAI,MAAM,yBAAyB,EACjD,GAAG,MAAMJ,EAAqB,sBAAsB,EAAE,kBACpDL,EAAKS,CAAK,CACZ,EAGA,MAAMC,EACJ,MAAMJ,EAAwB,UAAUC,CAAoB,EAG9D,OAAOF,EAAoB,oBAAoB,EAAE,qBAAqB,CACpE,QAASE,EAAqB,QAC9B,QAASA,EAAqB,OAChC,CAAC,EACD,OAAOG,CAAM,EAAE,QAAQ,CACrB,KAAMP,EAAqB,MAC3B,MAA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CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ContextFieldLoaderKind", "ClearSignContextType", "TokenContextFieldLoader", "mockTokenDataSource", "tokenContextFieldLoader", "mockTransactionField", "mockTokenPayload", "error", "result", "customField", "specificError", "emptyPayload"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ContextFieldLoaderKind } from \"@/shared/domain/ContextFieldLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionFieldContext } from \"@/shared/model/TransactionFieldContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextFieldLoader } from \"@/token/domain/TokenContextFieldLoader\";\n\ndescribe(\"TokenContextFieldLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const tokenContextFieldLoader = new TokenContextFieldLoader(\n mockTokenDataSource,\n );\n\n const mockTransactionField: TransactionFieldContext<ContextFieldLoaderKind.TOKEN> =\n {\n kind: ContextFieldLoaderKind.TOKEN,\n chainId: 1,\n address: \"0x1234567890abcdef\",\n };\n\n const mockTokenPayload = \"0x123456789abcdef0\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid token field\", () => {\n // GIVEN\n const validField = {\n kind: ContextFieldLoaderKind.TOKEN,\n chainId: 1,\n address: \"0x1234567890abcdef\",\n };\n\n // THEN\n expect(tokenContextFieldLoader.canHandle(validField)).toBe(true);\n });\n\n describe(\"should return false for invalid fields\", () => {\n const invalidFields = [\n { name: \"null\", value: null },\n { name: \"undefined\", value: undefined },\n { name: \"string\", value: \"invalid\" },\n { name: \"number\", value: 123 },\n { name: \"boolean\", value: true },\n { name: \"array\", value: [] },\n { name: \"empty object\", value: {} },\n {\n name: \"object missing kind\",\n value: { chainId: 1, address: \"0x123\" },\n },\n {\n name: \"object missing chainId\",\n value: { kind: ContextFieldLoaderKind.TOKEN, address: \"0x123\" },\n },\n {\n name: \"object missing address\",\n value: { kind: ContextFieldLoaderKind.TOKEN, chainId: 1 },\n },\n {\n name: \"object with wrong kind\",\n value: {\n kind: ContextFieldLoaderKind.NFT,\n chainId: 1,\n address: \"0x123\",\n },\n },\n ];\n\n test.each(invalidFields)(\"$name\", ({ value }) => {\n expect(tokenContextFieldLoader.canHandle(value)).toBe(false);\n });\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when token data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Token data source error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n });\n\n it(\"should return token context when successful\", async () => {\n // GIVEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should handle different chain IDs and addresses correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n chainId: 137,\n address: \"0xdeadbeef\",\n };\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result = await tokenContextFieldLoader.loadField(customField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: \"0xdeadbeef\",\n chainId: 137,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should preserve error message from token data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(specificError),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty token payload\", async () => {\n // GIVEN\n const emptyPayload = \"\";\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(emptyPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: emptyPayload,\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,0BAAAC,MAA8B,qCACvC,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,2BAAAC,MAA+B,yCAExC,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAA0B,IAAIF,EAClCC,CACF,EAEME,EACJ,CACE,KAAML,EAAuB,MAC7B,QAAS,EACT,QAAS,oBACX,EAEIM,EAAmB,qBAEzB,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,GAAG,2CAA4C,IAAM,CAEnD,MAAMC,EAAa,CACjB,KAAMP,EAAuB,MAC7B,QAAS,EACT,QAAS,oBACX,EAGA,OAAOI,EAAwB,UAAUG,CAAU,CAAC,EAAE,KAAK,EAAI,CACjE,CAAC,EAED,SAAS,yCAA0C,IAAM,CACvD,MAAMC,EAAgB,CACpB,CAAE,KAAM,OAAQ,MAAO,IAAK,EAC5B,CAAE,KAAM,YAAa,MAAO,MAAU,EAC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qBAAqB,CACpE,QAASE,EAAqB,QAC9B,QAASA,EAAqB,OAChC,CAAC,EACD,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,QAASK,CACX,CAAC,CACH,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,MAAMM,EAAc,CAClB,GAAGP,EACH,QAAS,IACT,QAAS,YACX,EACA,GAAG,MAAMF,EAAqB,sBAAsB,EAAE,kBACpDJ,EAAMO,CAAgB,CACxB,EAGA,MAAMK,EAAS,MAAMP,EAAwB,UAAUQ,CAAW,EAGlE,OAAOT,EAAoB,oBAAoB,EAAE,qBAAqB,CACpE,QAAS,aACT,QAAS,GACX,CAAC,EACD,OAAOQ,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,QAASK,CACX,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMO,EAAgB,IAAI,MAAM,uBAAuB,EACvD,GAAG,MAAMV,EAAqB,sBAAsB,EAAE,kBACpDL,EAAKe,CAAa,CACpB,EAGA,MAAMF,EACJ,MAAMP,EAAwB,UAAUC,CAAoB,EAG9D,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,MAAOY,CACT,CAAC,CACH,CAAC,EAED,GAAG,oCAAqC,SAAY,CAElD,MAAMC,EAAe,GACrB,GAAG,MAAMX,EAAqB,sBAAsB,EAAE,kBACpDJ,EAAMe,CAAY,CACpB,EAGA,MAAMH,EACJ,MAAMP,EAAwB,UAAUC,CAAoB,EAG9D,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,QAASa,CACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ContextFieldLoaderKind", "ClearSignContextType", "TokenContextFieldLoader", "mockTokenDataSource", "tokenContextFieldLoader", "mockTransactionField", "mockTokenPayload", "validField", "invalidFields", "value", "error", "result", "customField", "specificError", "emptyPayload"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var S=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?I(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&S(e,t,i),i},u=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as T}from"../../shared/model/SignatureTags";import{HexStringUtils as E}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let y=class{constructor(e,t){this.config=e;this._certificateLoader=t}async getTransactionDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:"commit:ff75b9427f79c04c09d0b4378d6e01e2e6113e28"},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpTransactionDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const D=s.transaction_info.descriptor.data,V=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:E.appendSignatureToPayload(D,V,T),certificate:C},d=[];for(const[p,b]of Object.entries(s.enums))for(const[P,{data:v,signatures:N}]of Object.entries(b))d.push({type:f.ENUM,id:Number(p),value:Number(P),payload:E.appendSignatureToPayload(v,N[this.config.cal.mode],T),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...d,..._])}return c(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};y=h([R(),u(0,m(x.Config)),u(1,m(O.PkiCertificateLoader))],y);export{y as HttpTransactionDataSource};
1
+ var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?S(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&I(e,t,i),i},y=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as T}from"../../shared/model/SignatureTags";import{HexStringUtils as D}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let u=class{constructor(e,t){this.config=e;this._certificateLoader=t}async getTransactionDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:"commit:cdd7d0f9cec33eb969a12641810cc7b06efeec1c"},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpTransactionDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const E=s.transaction_info.descriptor.data,V=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:D.appendSignatureToPayload(E,V,T),certificate:C},d=[];for(const[p,b]of Object.entries(s.enums))for(const[P,{data:v,signatures:N}]of Object.entries(b))d.push({type:f.ENUM,id:Number(p),value:Number(P),payload:D.appendSignatureToPayload(v,N[this.config.cal.mode],T),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...d,..._])}return c(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount))&&(e.param.spender===void 0||this.isDescriptorValueV1(e.param.spender))&&(e.param.chainId===void 0||this.isDescriptorValueV1(e.param.chainId)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};u=h([R(),y(0,m(x.Config)),y(1,m(O.PkiCertificateLoader))],u);export{u as HttpTransactionDataSource};
2
2
  //# sourceMappingURL=HttpTransactionDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpTransactionDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n // TODO revert to branch\n ref: `commit:ff75b9427f79c04c09d0b4378d6e01e2e6113e28`,\n },\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] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
- "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAE5BC,EACjB,CAH6C,YAAAD,EAE5B,wBAAAC,CAChB,CA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ACtE,OACE,OAAOA,GAAS,WACfA,EAAK,OAAS,OACZA,EAAK,OAAS,SAAW,OAAOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EA9Ya9B,EAAN8C,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAH5BnD",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n // TODO revert to branch\n ref: `commit:cdd7d0f9cec33eb969a12641810cc7b06efeec1c`,\n },\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] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS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ACdA,EAAK,OAAS,QACdA,EAAK,YAAY,OAAS,aAC1B,CAAC,OAAQ,KAAM,OAAO,EAAE,SAASA,EAAK,YAAY,KAAK,GACtDA,EAAK,YAAY,OAAS,QACzB,MAAM,QAAQA,EAAK,YAAY,QAAQ,GACvCA,EAAK,YAAY,SAAS,MAAOe,GAAM,KAAK,gBAAgBA,CAAC,CAAC,EAEtE,CAEQ,gBAAgBf,EAAgD,CACtE,OACE,OAAOA,GAAS,WACfA,EAAK,OAAS,OACZA,EAAK,OAAS,SAAW,OAAOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EAlZa9B,EAAN8C,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAH5BnD",
6
6
  "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpTransactionDataSource", "config", "_certificateLoader", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "ClearSignContextReferenceType", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var D=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=(i,t,e,a)=>{for(var r=a>1?void 0:a?S(t,e):t,n=i.length-1,s;n>=0;n--)(s=i[n])&&(r=(a?s(t,e,r):s(r))||r);return a&&r&&D(t,e,r),r},l=(i,t)=>(e,a)=>t(e,a,i);import{DeviceModelId as P,isHexaString as R}from"@ledgerhq/device-management-kit";import{inject as g,injectable as T}from"inversify";import{proxyTypes as v}from"../../proxy/di/proxyTypes";import{ClearSignContextType as d}from"../../shared/model/ClearSignContext";import{transactionTypes as A}from"../../transaction/di/transactionTypes";let c=class{constructor(t,e){this.transactionDataSource=t;this.proxyDataSource=e}async load(t){if(t.deviceModelId===P.NANO_S)return[];const{to:e,data:a,selector:r,chainId:n,deviceModelId:s}=t;if(e===void 0)return[];if(!R(r))return[{type:d.ERROR,error:new Error("Invalid selector")}];const x=await this.proxyDataSource.getProxyDelegateCall({calldata:a,proxyAddress:e,chainId:n,challenge:""}),[m,y]=x.caseOf({Left:()=>[e,void 0],Right:o=>[o.delegateAddresses.find(C=>C===e)||o.delegateAddresses[0],o.signedDescriptor]}),f=y?[{type:d.PROXY_DELEGATE_CALL,payload:"0x"}]:[],u=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:s,address:m,chainId:n,selector:r})).caseOf({Left:o=>[{type:d.ERROR,error:o}],Right:o=>o});return[...f,...u]}};c=p([T(),l(0,g(A.TransactionDataSource)),l(1,g(v.ProxyDataSource))],c);export{c as TransactionContextLoader};
1
+ var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=(s,e,t,o)=>{for(var r=o>1?void 0:o?f(e,t):e,a=s.length-1,n;a>=0;a--)(n=s[a])&&(r=(o?n(e,t,r):n(r))||r);return o&&r&&u(e,t,r),r},l=(s,e)=>(t,o)=>e(t,o,s);import{DeviceModelId as S,isHexaString as C}from"@ledgerhq/device-management-kit";import{inject as y,injectable as g}from"inversify";import{proxyTypes as D}from"../../proxy/di/proxyTypes";import{ClearSignContextType as i}from"../../shared/model/ClearSignContext";import{transactionTypes as R}from"../../transaction/di/transactionTypes";let d=class{constructor(e,t){this.transactionDataSource=e;this.proxyDataSource=t}async load(e){if(e.deviceModelId===S.NANO_S)return[];const{to:t,data:o,selector:r,chainId:a,deviceModelId:n}=e;if(t===void 0)return[];if(!C(r))return[{type:i.ERROR,error:new Error("Invalid selector")}];const p=await this.transactionDataSource.getTransactionDescriptors({deviceModelId:n,address:t,chainId:a,selector:r});return p.isRight()&&p.extract().length>0?p.extract():(await this.proxyDataSource.getProxyImplementationAddress({calldata:o,proxyAddress:t,chainId:a,challenge:""})).caseOf({Right:async({implementationAddress:c})=>{if(!c)return[{type:i.ERROR,error:new Error(`[ContextModule] TransactionContextLoader: No delegate address found for proxy ${t}`)}];const x=await this.transactionDataSource.getTransactionDescriptors({deviceModelId:n,address:c,chainId:a,selector:r});return x.isRight()&&x.extract().length>0?[{type:i.PROXY_DELEGATE_CALL,payload:"0x"},...x.extract()]:[{type:i.ERROR,error:new Error(`[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call ${c}`)}]},Left:c=>Promise.resolve([{type:i.ERROR,error:new Error(`[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address ${t}`)}])})}};d=m([g(),l(0,y(R.TransactionDataSource)),l(1,y(D.ProxyDataSource))],d);export{d 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 { DeviceModelId, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type { ProxyDataSource } from \"@/proxy/data/HttpProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ProxyDelegateCall } from \"@/proxy/model/ProxyDelegateCall\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\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(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined) {\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: \"\",\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 const proxyDelegateCallContext: ClearSignContext[] =\n proxyDelegateCallDescriptor\n ? [\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n // This payload is not used as the clear sign context is not used, only the subcontext that will be\n // fetched during the provide, with a correct challenge\n payload: \"0x\",\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,UAAAC,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,cAAAC,MAAkB,wBAG3B,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,oCAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAEAC,EACR,CAHQ,2BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkBC,EAAc,OACtC,MAAO,CAAC,EAGV,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIN,EACvD,GAAIE,IAAO,OACT,MAAO,CAAC,EAGV,GAAI,CAACK,EAAaH,CAAQ,EACxB,MAAO,CACL,CACE,KAAMI,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,MAAMC,EAAoB,MAAM,KAAK,gBAAgB,qBAAqB,CACxE,SAAUN,EACV,aAAcD,EACd,QAAAG,EACA,UAAW,EACb,CAAC,EASK,CAACK,EAAiBC,CAA2B,EAG/CF,EAAkB,OAAO,CAC3B,KAAM,IAAM,CAACP,EAAK,MAAS,EAC3B,MAAQU,GACC,CACLA,EAAU,kBAAkB,KAAMC,GAAYA,IAAYX,CAAE,GAC1DU,EAAU,kBAAkB,CAAC,EAC/BA,EAAU,gBACZ,CAEJ,CAAC,EAEKE,EACJH,EACI,CACE,CACE,KAAMH,EAAqB,oBAG3B,QAAS,IACX,CACF,EACA,CAAC,EAEDO,GACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAT,EACA,QAASI,EACT,QAAAL,EACA,SAAAD,CACF,CAAC,GACD,OAAO,CACP,KAAOY,GAA8B,CACnC,CACE,KAAMR,EAAqB,MAC3B,MAAAQ,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAED,MAAO,CAAC,GAAGH,EAA0B,GAAGC,CAAmB,CAC7D,CACF,EAtFalB,EAANqB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IAJzB1B",
6
- "names": ["DeviceModelId", "isHexaString", "inject", "injectable", "proxyTypes", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "ctx", "DeviceModelId", "to", "data", "selector", "chainId", "deviceModelId", "isHexaString", "ClearSignContextType", "proxyDelegateCall", "resolvedAddress", "proxyDelegateCallDescriptor", "proxyData", "address", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "proxyTypes"]
4
+ "sourcesContent": ["import { DeviceModelId, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type {\n ProxyDataSource,\n ProxyImplementationAddress,\n} from \"@/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\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(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined) {\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 // try to fetch the transaction descriptors from the transaction data source\n // using the smart contract address to\n const transactionContexts =\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: to,\n chainId,\n selector,\n });\n\n if (\n transactionContexts.isRight() &&\n transactionContexts.extract().length > 0\n ) {\n return transactionContexts.extract();\n }\n\n // if the transaction descriptors are not found, try to fetch the proxy delegate call\n // and return the proxy delegate call context\n const proxyImplementationAddress =\n await this.proxyDataSource.getProxyImplementationAddress({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: \"\",\n });\n\n return proxyImplementationAddress.caseOf<Promise<ClearSignContext[]>>({\n Right: async ({ implementationAddress }: ProxyImplementationAddress) => {\n if (!implementationAddress) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `[ContextModule] TransactionContextLoader: No delegate address found for proxy ${to}`,\n ),\n },\n ];\n }\n\n const transactionProxyContexts =\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: implementationAddress,\n chainId,\n selector,\n });\n\n if (\n transactionProxyContexts.isRight() &&\n transactionProxyContexts.extract().length > 0\n ) {\n return [\n // This payload is not used as the clear sign context is not used, only the subcontext that will be\n // fetched during the provide, with a correct challenge\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x\",\n },\n ...transactionProxyContexts.extract(),\n ];\n }\n\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call ${implementationAddress}`,\n ),\n },\n ];\n },\n Left: (_) => {\n return Promise.resolve([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address ${to}`,\n ),\n },\n ]);\n },\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,iBAAAA,EAAe,gBAAAC,MAAoB,kCAC5C,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAMnC,OAAS,cAAAC,MAAkB,wBAE3B,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,oCAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAEAC,EACR,CAHQ,2BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkBC,EAAc,OACtC,MAAO,CAAC,EAGV,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIN,EACvD,GAAIE,IAAO,OACT,MAAO,CAAC,EAGV,GAAI,CAACK,EAAaH,CAAQ,EACxB,MAAO,CACL,CACE,KAAMI,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAKF,MAAMC,EACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAH,EACA,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,EAEH,OACEK,EAAoB,QAAQ,GAC5BA,EAAoB,QAAQ,EAAE,OAAS,EAEhCA,EAAoB,QAAQ,GAMnC,MAAM,KAAK,gBAAgB,8BAA8B,CACvD,SAAUN,EACV,aAAcD,EACd,QAAAG,EACA,UAAW,EACb,CAAC,GAE+B,OAAoC,CACpE,MAAO,MAAO,CAAE,sBAAAK,CAAsB,IAAkC,CACtE,GAAI,CAACA,EACH,MAAO,CACL,CACE,KAAMF,EAAqB,MAC3B,MAAO,IAAI,MACT,iFAAiFN,CAAE,EACrF,CACF,CACF,EAGF,MAAMS,EACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAL,EACA,QAASI,EACT,QAAAL,EACA,SAAAD,CACF,CAAC,EAEH,OACEO,EAAyB,QAAQ,GACjCA,EAAyB,QAAQ,EAAE,OAAS,EAErC,CAGL,CACE,KAAMH,EAAqB,oBAC3B,QAAS,IACX,EACA,GAAGG,EAAyB,QAAQ,CACtC,EAGK,CACL,CACE,KAAMH,EAAqB,MAC3B,MAAO,IAAI,MACT,sHAAsHE,CAAqB,EAC7I,CACF,CACF,CACF,EACA,KAAOE,GACE,QAAQ,QAAQ,CACrB,CACE,KAAMJ,EAAqB,MAC3B,MAAO,IAAI,MACT,4FAA4FN,CAAE,EAChG,CACF,CACF,CAAC,CAEL,CAAC,CACH,CACF,EA/GaL,EAANgB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IAJzBrB",
6
+ "names": ["DeviceModelId", "isHexaString", "inject", "injectable", "proxyTypes", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "ctx", "DeviceModelId", "to", "data", "selector", "chainId", "deviceModelId", "isHexaString", "ClearSignContextType", "transactionContexts", "implementationAddress", "transactionProxyContexts", "_", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "proxyTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as c,Right as n}from"purify-ts";import{ClearSignContextType as e}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as i}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const r=vi.fn(),s=vi.fn(),d={getTransactionDescriptors:r},l={getProxyDelegateCall:s,getProxyImplementationAddress:vi.fn()},o=new i(d,l);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 'to' is undefined",async()=>{const a={to:void 0,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()=>{s.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(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.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(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({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:"0x"},{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(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({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:"0x"},{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(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({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:"0x"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
1
+ import{DeviceModelId as i}from"@ledgerhq/device-management-kit";import{Left as c,Right as s}from"purify-ts";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as x}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const o=vi.fn(),n=vi.fn(),d={getTransactionDescriptors:o},l={getProxyImplementationAddress:n},r=new x(d,l);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const e={},t=await r.load(e);expect(t).toEqual([])}),it("should return an empty array if 'to' is undefined",async()=>{const e={to:void 0,data:"0x"},t=await r.load(e);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const e={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await r.load(e);expect(t).toEqual([{type:a.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{n.mockResolvedValue(c(new Error("data source error"))),o.mockResolvedValue(c(new Error("data source error")));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(o).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address 0x7")}])}),it("should return the contexts on success",async()=>{o.mockResolvedValue(s([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(c(new Error("data source error")));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{o.mockResolvedValueOnce(s([])),o.mockResolvedValue(s([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({implementationAddress:"0x1234567890abcdef",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([{type:a.PROXY_DELEGATE_CALL,payload:"0x"},{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return an empty array if device model is NANO_S",async()=>{const e={deviceModelId:i.NANO_S,to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([]),expect(o).not.toHaveBeenCalled(),expect(n).not.toHaveBeenCalled()}),it("should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail",async()=>{o.mockResolvedValueOnce(s([])),o.mockResolvedValueOnce(c(new Error("data source error"))),n.mockResolvedValue(s({implementationAddress:"0xResolvedAddress",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(o).toHaveBeenCalledTimes(2),expect(o).toHaveBeenNthCalledWith(2,{address:"0xResolvedAddress",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call 0xResolvedAddress")}])})});
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 { ProxyDataSource } from \"@/proxy/data/HttpProxyDataSource\";\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 loader = new TransactionContextLoader(\n mockTransactionDataSource,\n mockProxyDatasource,\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 'to' is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, 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: \"0x\",\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: \"0x\",\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: \"0x\",\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,wBAA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X,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,CACrB,CACE,KAAMR,EAAqB,oBAC3B,QAAS,IACX,EACA,CACE,KAAMA,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,CACrB,CACE,KAAMR,EAAqB,oBAC3B,QAAS,IACX,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", "loader", "transaction", "result"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\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 getProxyImplementationAddress = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyImplementationAddress: getProxyImplementationAddress,\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n mockProxyDatasource,\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 'to' is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, 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 getProxyImplementationAddress.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(\n \"[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address 0x7\",\n ),\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 getProxyImplementationAddress.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.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\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 getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0x1234567890abcdef\",\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: \"0x\",\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 an empty array if device model is NANO_S\", async () => {\n // GIVEN\n const transaction = {\n deviceModelId: DeviceModelId.NANO_S,\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 expect(getTransactionDescriptorsMock).not.toHaveBeenCalled();\n expect(getProxyImplementationAddress).not.toHaveBeenCalled();\n });\n\n it(\"should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getTransactionDescriptorsMock.mockResolvedValueOnce(\n Left(new Error(\"data source error\")),\n ); // Second call fails\n getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0xResolvedAddress\",\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(getTransactionDescriptorsMock).toHaveBeenCalledTimes(2);\n expect(getTransactionDescriptorsMock).toHaveBeenNthCalledWith(2, {\n address: \"0xResolvedAddress\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call 0xResolvedAddress\",\n ),\n },\n ]);\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,4BAAAC,MAAgC,gDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAAgC,GAAG,GAAG,EACtCC,EAAmD,CACvD,0BAA2BF,CAC7B,EACMG,EAAuC,CAC3C,8BAA+BF,CACjC,EACMG,EAAS,IAAIL,EACjBG,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,CAAC,CAC3B,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMD,EAAc,CAAE,GAAI,OAAW,KAAM,IAAK,EAG1CC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gDAAiD,SAAY,CAE9D,MAAMD,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,wEACR,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMR,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,EAED,GAAG,8CAA+C,SAAY,CAE5DG,EAA8B,kBAC5BL,EAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACAI,EAA8B,kBAC5BJ,EAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACA,MAAMS,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,y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C3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,yDAA0D,SAAY,CAEvE,MAAMO,EAAc,CAClB,cAAeV,EAAc,OAC7B,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMW,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,EACzB,OAAON,CAA6B,EAAE,IAAI,iBAAiB,EAC3D,OAAOC,CAA6B,EAAE,IAAI,iBAAiB,CAC7D,CAAC,EAED,GAAG,iHAAkH,SAAY,CAE/HD,EAA8B,sBAAsBH,EAAM,CAAC,CAAC,CAAC,EAC7DG,EAA8B,sBAC5BJ,EAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACAK,EAA8B,kBAC5BJ,EAAM,CACJ,sBAAuB,oBACvB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMQ,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOL,CAA6B,EAAE,sBAAsB,CAAC,EAC7D,OAAOA,CAA6B,EAAE,wBAAwB,EAAG,CAC/D,QAAS,oBACT,QAAS,EACT,SAAU,YACZ,CAAC,EACD,OAAOM,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMR,EAAqB,MAC3B,MAAO,IAAI,MACT,sIACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyImplementationAddress", "mockTransactionDataSource", "mockProxyDatasource", "loader", "transaction", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var m=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var s=(r,e,o,t)=>{for(var a=t>1?void 0:t?p(e,o):e,i=r.length-1,d;i>=0;i--)(d=r[i])&&(a=(t?d(e,o,a):d(a))||a);return t&&a&&m(e,o,a),a},c=(r,e)=>(o,t)=>e(o,t,r);import{inject as S,injectable as T}from"inversify";import{ContextFieldLoaderKind as C}from"../../shared/domain/ContextFieldLoader";import{ClearSignContextType as l}from"../../shared/model/ClearSignContext";import{trustedNameTypes as u}from"../../trusted-name/di/trustedNameTypes";let n=class{constructor(e){this._dataSource=e}kind=C.TRUSTED_NAME;async loadField(e){return(await this._dataSource.getTrustedNamePayload({chainId:e.chainId,address:e.address,challenge:e.challenge,types:e.types,sources:e.sources})).caseOf({Left:t=>({type:l.ERROR,error:t}),Right:t=>({type:l.TRUSTED_NAME,payload:t})})}};n=s([T(),c(0,S(u.TrustedNameDataSource))],n);export{n as TrustedNameContextFieldLoader};
1
+ var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var c=(r,e,n,t)=>{for(var a=t>1?void 0:t?m(e,n):e,o=r.length-1,i;o>=0;o--)(i=r[o])&&(a=(t?i(e,n,a):i(a))||a);return t&&a&&p(e,n,a),a},d=(r,e)=>(n,t)=>e(n,t,r);import{inject as l,injectable as g}from"inversify";import{ContextFieldLoaderKind as y}from"../../shared/domain/ContextFieldLoader";import{ClearSignContextType as u}from"../../shared/model/ClearSignContext";import{trustedNameTypes as S}from"../../trusted-name/di/trustedNameTypes";let s=class{constructor(e){this._dataSource=e}canHandle(e){return typeof e=="object"&&e!==null&&"kind"in e&&e.kind===y.TRUSTED_NAME&&"chainId"in e&&"address"in e&&"challenge"in e&&"types"in e&&"sources"in e}async loadField(e){return(await this._dataSource.getTrustedNamePayload({chainId:e.chainId,address:e.address,challenge:e.challenge,types:e.types,sources:e.sources})).caseOf({Left:t=>({type:u.ERROR,error:t}),Right:t=>({type:u.TRUSTED_NAME,payload:t})})}};s=c([g(),d(0,l(S.TrustedNameDataSource))],s);export{s as TrustedNameContextFieldLoader};
2
2
  //# sourceMappingURL=TrustedNameContextFieldLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/domain/TrustedNameContextFieldLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport {\n ContextFieldLoader,\n ContextFieldLoaderKind,\n} from \"@/shared/domain/ContextFieldLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionFieldContext } from \"@/shared/model/TransactionFieldContext\";\nimport * as TrustedNameDataSource from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\n@injectable()\nexport class TrustedNameContextFieldLoader\n implements ContextFieldLoader<ContextFieldLoaderKind.TRUSTED_NAME>\n{\n kind: ContextFieldLoaderKind.TRUSTED_NAME =\n ContextFieldLoaderKind.TRUSTED_NAME;\n\n constructor(\n @inject(trustedNameTypes.TrustedNameDataSource)\n private _dataSource: TrustedNameDataSource.TrustedNameDataSource,\n ) {}\n\n async loadField(\n field: TransactionFieldContext<ContextFieldLoaderKind.TRUSTED_NAME>,\n ): Promise<ClearSignContext> {\n const payload = await this._dataSource.getTrustedNamePayload({\n chainId: field.chainId,\n address: field.address,\n challenge: field.challenge,\n types: field.types,\n sources: field.sources,\n });\n return payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: value,\n }),\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAEE,0BAAAC,MACK,qCACP,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,qCAG1B,IAAMC,EAAN,KAEP,CAIE,YAEUC,EACR,CADQ,iBAAAA,CACP,CANH,KACEC,EAAuB,aAOzB,MAAM,UACJC,EAC2B,CAQ3B,OAPgB,MAAM,KAAK,YAAY,sBAAsB,CAC3D,QAASA,EAAM,QACf,QAASA,EAAM,QACf,UAAWA,EAAM,UACjB,MAAOA,EAAM,MACb,QAASA,EAAM,OACjB,CAAC,GACc,OAAO,CACpB,KAAOC,IAA6B,CAClC,KAAMC,EAAqB,MAC3B,MAAAD,CACF,GACA,MAAQE,IAA6B,CACnC,KAAMD,EAAqB,aAC3B,QAASC,CACX,EACF,CAAC,CACH,CACF,EAhCaN,EAANO,EAAA,CADNC,EAAW,EAQPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,IAPrCX",
6
- "names": ["inject", "injectable", "ContextFieldLoaderKind", "ClearSignContextType", "trustedNameTypes", "TrustedNameContextFieldLoader", "_dataSource", "ContextFieldLoaderKind", "field", "error", "ClearSignContextType", "value", "__decorateClass", "injectable", "__decorateParam", "inject", "trustedNameTypes"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport {\n ContextFieldLoader,\n ContextFieldLoaderKind,\n} from \"@/shared/domain/ContextFieldLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport * as TrustedNameDataSource from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\ntype TrustedNameFieldInput = {\n kind: ContextFieldLoaderKind.TRUSTED_NAME;\n chainId: number;\n address: string;\n challenge: string;\n types: string[];\n sources: string[];\n};\n\n@injectable()\nexport class TrustedNameContextFieldLoader\n implements ContextFieldLoader<TrustedNameFieldInput>\n{\n constructor(\n @inject(trustedNameTypes.TrustedNameDataSource)\n private _dataSource: TrustedNameDataSource.TrustedNameDataSource,\n ) {}\n\n canHandle(field: unknown): field is TrustedNameFieldInput {\n return (\n typeof field === \"object\" &&\n field !== null &&\n \"kind\" in field &&\n field.kind === ContextFieldLoaderKind.TRUSTED_NAME &&\n \"chainId\" in field &&\n \"address\" in field &&\n \"challenge\" in field &&\n \"types\" in field &&\n \"sources\" in field\n );\n }\n\n async loadField(field: TrustedNameFieldInput): Promise<ClearSignContext> {\n const payload = await this._dataSource.getTrustedNamePayload({\n chainId: field.chainId,\n address: field.address,\n challenge: field.challenge,\n types: field.types,\n sources: field.sources,\n });\n return payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: value,\n }),\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAEE,0BAAAC,MACK,qCACP,OAEE,wBAAAC,MACK,kCAEP,OAAS,oBAAAC,MAAwB,qCAY1B,IAAMC,EAAN,KAEP,CACE,YAEUC,EACR,CADQ,iBAAAA,CACP,CAEH,UAAUC,EAAgD,CACxD,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,SAAUA,GACVA,EAAM,OAASC,EAAuB,cACtC,YAAaD,GACb,YAAaA,GACb,cAAeA,GACf,UAAWA,GACX,YAAaA,CAEjB,CAEA,MAAM,UAAUA,EAAyD,CAQvE,OAPgB,MAAM,KAAK,YAAY,sBAAsB,CAC3D,QAASA,EAAM,QACf,QAASA,EAAM,QACf,UAAWA,EAAM,UACjB,MAAOA,EAAM,MACb,QAASA,EAAM,OACjB,CAAC,GACc,OAAO,CACpB,KAAOE,IAA6B,CAClC,KAAMC,EAAqB,MAC3B,MAAAD,CACF,GACA,MAAQE,IAA6B,CACnC,KAAMD,EAAqB,aAC3B,QAASC,CACX,EACF,CAAC,CACH,CACF,EAzCaN,EAANO,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,IAJrCX",
6
+ "names": ["inject", "injectable", "ContextFieldLoaderKind", "ClearSignContextType", "trustedNameTypes", "TrustedNameContextFieldLoader", "_dataSource", "field", "ContextFieldLoaderKind", "error", "ClearSignContextType", "value", "__decorateClass", "injectable", "__decorateParam", "inject", "trustedNameTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as c,Right as r}from"purify-ts";import{ContextFieldLoaderKind as n}from"../../shared/domain/ContextFieldLoader";import{ClearSignContextType as l}from"../../shared/model/ClearSignContext";import{TrustedNameContextFieldLoader as i}from"../../trusted-name/domain/TrustedNameContextFieldLoader";describe("TrustedNameContextFieldLoader",()=>{const t={getTrustedNamePayload:vi.fn(),getDomainNamePayload:vi.fn()},d=new i(t),e={kind:n.TRUSTED_NAME,chainId:1,address:"0x1234567890abcdef",challenge:"test-challenge",types:["contract","token"],sources:["ledger","ens"]},o="0x123456789abcdef0";beforeEach(()=>{vi.resetAllMocks()}),describe("constructor",()=>{it("should initialize with correct kind",()=>{expect(d.kind).toBe(n.TRUSTED_NAME)})}),describe("loadField",()=>{it("should return error context when trusted name data source fails",async()=>{const a=new Error("Trusted name data source error");vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(a));const s=await d.loadField(e);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:e.types,sources:e.sources}),expect(s).toEqual({type:l.ERROR,error:a})}),it("should return trusted name context when successful",async()=>{vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(o));const a=await d.loadField(e);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:e.types,sources:e.sources}),expect(a).toEqual({type:l.TRUSTED_NAME,payload:o})}),it("should handle different chain IDs and addresses correctly",async()=>{const a={...e,chainId:137,address:"0xdeadbeef",challenge:"custom-challenge"};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(o));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:137,address:"0xdeadbeef",challenge:"custom-challenge",types:e.types,sources:e.sources}),expect(s).toEqual({type:l.TRUSTED_NAME,payload:o})}),it("should handle different types and sources correctly",async()=>{const a={...e,types:["wallet","exchange"],sources:["coingecko","1inch"]};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(o));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:["wallet","exchange"],sources:["coingecko","1inch"]}),expect(s).toEqual({type:l.TRUSTED_NAME,payload:o})}),it("should preserve error message from trusted name data source",async()=>{const a=new Error("Network timeout error");vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(a));const s=await d.loadField(e);expect(s).toEqual({type:l.ERROR,error:a})}),it("should handle empty trusted name payload",async()=>{const a="";vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(a));const s=await d.loadField(e);expect(s).toEqual({type:l.TRUSTED_NAME,payload:a})}),it("should handle empty types and sources arrays",async()=>{const a={...e,types:[],sources:[]};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(o));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:[],sources:[]}),expect(s).toEqual({type:l.TRUSTED_NAME,payload:o})}),it("should handle single type and source",async()=>{const a={...e,types:["contract"],sources:["ens"]};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(o));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:["contract"],sources:["ens"]}),expect(s).toEqual({type:l.TRUSTED_NAME,payload:o})})})});
1
+ import{Left as r,Right as c}from"purify-ts";import{ContextFieldLoaderKind as n}from"../../shared/domain/ContextFieldLoader";import{ClearSignContextType as o}from"../../shared/model/ClearSignContext";import{TrustedNameContextFieldLoader as i}from"../../trusted-name/domain/TrustedNameContextFieldLoader";describe("TrustedNameContextFieldLoader",()=>{const t={getTrustedNamePayload:vi.fn(),getDomainNamePayload:vi.fn()},d=new i(t),e={kind:n.TRUSTED_NAME,chainId:1,address:"0x1234567890abcdef",challenge:"test-challenge",types:["contract","token"],sources:["ledger","ens"]},l="0x123456789abcdef0";beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle",()=>{it("should return true for valid trusted name field",()=>{const a={kind:n.TRUSTED_NAME,chainId:1,address:"0x1234567890abcdef",challenge:"test-challenge",types:["contract","token"],sources:["ledger","ens"]};expect(d.canHandle(a)).toBe(!0)}),describe("should return false for invalid fields",()=>{const a=[{name:"null",value:null},{name:"undefined",value:void 0},{name:"string",value:"invalid"},{name:"number",value:123},{name:"boolean",value:!0},{name:"array",value:[]},{name:"empty object",value:{}},{name:"object missing kind",value:{chainId:1,address:"0x123",challenge:"test",types:["contract"],sources:["ledger"]}},{name:"object missing chainId",value:{kind:n.TRUSTED_NAME,address:"0x123",challenge:"test",types:["contract"],sources:["ledger"]}},{name:"object missing address",value:{kind:n.TRUSTED_NAME,chainId:1,challenge:"test",types:["contract"],sources:["ledger"]}},{name:"object missing challenge",value:{kind:n.TRUSTED_NAME,chainId:1,address:"0x123",types:["contract"],sources:["ledger"]}},{name:"object missing types",value:{kind:n.TRUSTED_NAME,chainId:1,address:"0x123",challenge:"test",sources:["ledger"]}},{name:"object missing sources",value:{kind:n.TRUSTED_NAME,chainId:1,address:"0x123",challenge:"test",types:["contract"]}},{name:"object with wrong kind",value:{kind:n.TOKEN,chainId:1,address:"0x123",challenge:"test",types:["contract"],sources:["ledger"]}}];test.each(a)("$name",({value:s})=>{expect(d.canHandle(s)).toBe(!1)})})}),describe("loadField",()=>{it("should return error context when trusted name data source fails",async()=>{const a=new Error("Trusted name data source error");vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(a));const s=await d.loadField(e);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:e.types,sources:e.sources}),expect(s).toEqual({type:o.ERROR,error:a})}),it("should return trusted name context when successful",async()=>{vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(l));const a=await d.loadField(e);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:e.types,sources:e.sources}),expect(a).toEqual({type:o.TRUSTED_NAME,payload:l})}),it("should handle different chain IDs and addresses correctly",async()=>{const a={...e,chainId:137,address:"0xdeadbeef",challenge:"custom-challenge"};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(l));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:137,address:"0xdeadbeef",challenge:"custom-challenge",types:e.types,sources:e.sources}),expect(s).toEqual({type:o.TRUSTED_NAME,payload:l})}),it("should handle different types and sources correctly",async()=>{const a={...e,types:["wallet","exchange"],sources:["coingecko","1inch"]};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(l));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:["wallet","exchange"],sources:["coingecko","1inch"]}),expect(s).toEqual({type:o.TRUSTED_NAME,payload:l})}),it("should preserve error message from trusted name data source",async()=>{const a=new Error("Network timeout error");vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(r(a));const s=await d.loadField(e);expect(s).toEqual({type:o.ERROR,error:a})}),it("should handle empty trusted name payload",async()=>{const a="";vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(a));const s=await d.loadField(e);expect(s).toEqual({type:o.TRUSTED_NAME,payload:a})}),it("should handle empty types and sources arrays",async()=>{const a={...e,types:[],sources:[]};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(l));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:[],sources:[]}),expect(s).toEqual({type:o.TRUSTED_NAME,payload:l})}),it("should handle single type and source",async()=>{const a={...e,types:["contract"],sources:["ens"]};vi.spyOn(t,"getTrustedNamePayload").mockResolvedValue(c(l));const s=await d.loadField(a);expect(t.getTrustedNamePayload).toHaveBeenCalledWith({chainId:e.chainId,address:e.address,challenge:e.challenge,types:["contract"],sources:["ens"]}),expect(s).toEqual({type:o.TRUSTED_NAME,payload:l})})})});
2
2
  //# sourceMappingURL=TrustedNameContextFieldLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/domain/TrustedNameContextFieldLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ContextFieldLoaderKind } from \"@/shared/domain/ContextFieldLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionFieldContext } from \"@/shared/model/TransactionFieldContext\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { TrustedNameContextFieldLoader } from \"@/trusted-name/domain/TrustedNameContextFieldLoader\";\n\ndescribe(\"TrustedNameContextFieldLoader\", () => {\n const mockTrustedNameDataSource: TrustedNameDataSource = {\n getTrustedNamePayload: vi.fn(),\n getDomainNamePayload: vi.fn(),\n };\n const trustedNameContextFieldLoader = new TrustedNameContextFieldLoader(\n mockTrustedNameDataSource,\n );\n\n const mockTransactionField: TransactionFieldContext<ContextFieldLoaderKind.TRUSTED_NAME> =\n {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n address: \"0x1234567890abcdef\",\n challenge: \"test-challenge\",\n types: [\"contract\", \"token\"],\n sources: [\"ledger\", \"ens\"],\n };\n\n const mockTrustedNamePayload = \"0x123456789abcdef0\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"constructor\", () => {\n it(\"should initialize with correct kind\", () => {\n // THEN\n expect(trustedNameContextFieldLoader.kind).toBe(\n ContextFieldLoaderKind.TRUSTED_NAME,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when trusted name data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Trusted name data source error\");\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Left(error));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: mockTransactionField.types,\n sources: mockTransactionField.sources,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n });\n\n it(\"should return trusted name context when successful\", async () => {\n // GIVEN\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: mockTransactionField.types,\n sources: mockTransactionField.sources,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should handle different chain IDs and addresses correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n chainId: 137,\n address: \"0xdeadbeef\",\n challenge: \"custom-challenge\",\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result = await trustedNameContextFieldLoader.loadField(customField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: 137,\n address: \"0xdeadbeef\",\n challenge: \"custom-challenge\",\n types: mockTransactionField.types,\n sources: mockTransactionField.sources,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should handle different types and sources correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n types: [\"wallet\", \"exchange\"],\n sources: [\"coingecko\", \"1inch\"],\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result = await trustedNameContextFieldLoader.loadField(customField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: [\"wallet\", \"exchange\"],\n sources: [\"coingecko\", \"1inch\"],\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should preserve error message from trusted name data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Left(specificError));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty trusted name payload\", async () => {\n // GIVEN\n const emptyPayload = \"\";\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(emptyPayload));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: emptyPayload,\n });\n });\n\n it(\"should handle empty types and sources arrays\", async () => {\n // GIVEN\n const fieldWithEmptyArrays = {\n ...mockTransactionField,\n types: [],\n sources: [],\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(fieldWithEmptyArrays);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: [],\n sources: [],\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should handle single type and source\", async () => {\n // GIVEN\n const fieldWithSingleElements = {\n ...mockTransactionField,\n types: [\"contract\"],\n sources: [\"ens\"],\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result = await trustedNameContextFieldLoader.loadField(\n fieldWithSingleElements,\n );\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: [\"contract\"],\n sources: [\"ens\"],\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,0BAAAC,MAA8B,qCACvC,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,iCAAAC,MAAqC,sDAE9C,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAmD,CACvD,sBAAuB,GAAG,GAAG,EAC7B,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAgC,IAAIF,EACxCC,CACF,EAEME,EACJ,CACE,KAAML,EAAuB,aAC7B,QAAS,EACT,QAAS,qBACT,UAAW,iBACX,MAAO,CAAC,WAAY,OAAO,EAC3B,QAAS,CAAC,SAAU,KAAK,CAC3B,EAEIM,EAAyB,qBAE/B,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,cAAe,IAAM,CAC5B,GAAG,sCAAuC,IAAM,CAE9C,OAAOF,EAA8B,IAAI,EAAE,KACzCJ,EAAuB,YACzB,CACF,CAAC,CACH,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,GAAG,kEAAmE,SAAY,CAEhF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ACET,EAA0B,qBAC5B,EAAE,qBAAqB,CACrB,QAASE,EAAqB,QAC9B,QAASA,EAAqB,QAC9B,UAAWA,EAAqB,UAChC,MAAO,CAAC,EACR,QAAS,CAAC,CACZ,CAAC,EACD,OAAOG,CAAM,EAAE,QAAQ,CACrB,KAAMP,EAAqB,aAC3B,QAASK,CACX,CAAC,CACH,CAAC,EAED,GAAG,uCAAwC,SAAY,CAErD,MAAMO,EAA0B,CAC9B,GAAGR,EACH,MAAO,CAAC,UAAU,EAClB,QAAS,CAAC,KAAK,CACjB,EACA,GAAG,MACDF,EACA,uBACF,EAAE,kBAAkBJ,EAAMO,CAAsB,CAAC,EAGjD,MAAME,EAAS,MAAMJ,EAA8B,UACjDS,CACF,EAGA,OACEV,EAA0B,qBAC5B,EAAE,qBAAqB,CACrB,QAASE,EAAqB,QAC9B,QAASA,EAAqB,QAC9B,UAAWA,EAAqB,UAChC,MAAO,CAAC,UAAU,EAClB,QAAS,CAAC,KAAK,CACjB,CAAC,EACD,OAAOG,CAAM,EAAE,QAAQ,CACrB,KAAMP,EAAqB,aAC3B,QAASK,CACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ContextFieldLoaderKind", "ClearSignContextType", "TrustedNameContextFieldLoader", "mockTrustedNameDataSource", "trustedNameContextFieldLoader", "mockTransactionField", "mockTrustedNamePayload", "error", "result", "customField", "specificError", "emptyPayload", "fieldWithEmptyArrays", "fieldWithSingleElements"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ContextFieldLoaderKind } from \"@/shared/domain/ContextFieldLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionFieldContext } from \"@/shared/model/TransactionFieldContext\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { TrustedNameContextFieldLoader } from \"@/trusted-name/domain/TrustedNameContextFieldLoader\";\n\ndescribe(\"TrustedNameContextFieldLoader\", () => {\n const mockTrustedNameDataSource: TrustedNameDataSource = {\n getTrustedNamePayload: vi.fn(),\n getDomainNamePayload: vi.fn(),\n };\n const trustedNameContextFieldLoader = new TrustedNameContextFieldLoader(\n mockTrustedNameDataSource,\n );\n\n const mockTransactionField: TransactionFieldContext<ContextFieldLoaderKind.TRUSTED_NAME> =\n {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n address: \"0x1234567890abcdef\",\n challenge: \"test-challenge\",\n types: [\"contract\", \"token\"],\n sources: [\"ledger\", \"ens\"],\n };\n\n const mockTrustedNamePayload = \"0x123456789abcdef0\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid trusted name field\", () => {\n // GIVEN\n const validField = {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n address: \"0x1234567890abcdef\",\n challenge: \"test-challenge\",\n types: [\"contract\", \"token\"],\n sources: [\"ledger\", \"ens\"],\n };\n\n // THEN\n expect(trustedNameContextFieldLoader.canHandle(validField)).toBe(true);\n });\n\n describe(\"should return false for invalid fields\", () => {\n const invalidFields = [\n { name: \"null\", value: null },\n { name: \"undefined\", value: undefined },\n { name: \"string\", value: \"invalid\" },\n { name: \"number\", value: 123 },\n { name: \"boolean\", value: true },\n { name: \"array\", value: [] },\n { name: \"empty object\", value: {} },\n {\n name: \"object missing kind\",\n value: {\n chainId: 1,\n address: \"0x123\",\n challenge: \"test\",\n types: [\"contract\"],\n sources: [\"ledger\"],\n },\n },\n {\n name: \"object missing chainId\",\n value: {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n address: \"0x123\",\n challenge: \"test\",\n types: [\"contract\"],\n sources: [\"ledger\"],\n },\n },\n {\n name: \"object missing address\",\n value: {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n challenge: \"test\",\n types: [\"contract\"],\n sources: [\"ledger\"],\n },\n },\n {\n name: \"object missing challenge\",\n value: {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n address: \"0x123\",\n types: [\"contract\"],\n sources: [\"ledger\"],\n },\n },\n {\n name: \"object missing types\",\n value: {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n address: \"0x123\",\n challenge: \"test\",\n sources: [\"ledger\"],\n },\n },\n {\n name: \"object missing sources\",\n value: {\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: 1,\n address: \"0x123\",\n challenge: \"test\",\n types: [\"contract\"],\n },\n },\n {\n name: \"object with wrong kind\",\n value: {\n kind: ContextFieldLoaderKind.TOKEN,\n chainId: 1,\n address: \"0x123\",\n challenge: \"test\",\n types: [\"contract\"],\n sources: [\"ledger\"],\n },\n },\n ];\n\n test.each(invalidFields)(\"$name\", ({ value }) => {\n expect(trustedNameContextFieldLoader.canHandle(value)).toBe(false);\n });\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when trusted name data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Trusted name data source error\");\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Left(error));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: mockTransactionField.types,\n sources: mockTransactionField.sources,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n });\n\n it(\"should return trusted name context when successful\", async () => {\n // GIVEN\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: mockTransactionField.types,\n sources: mockTransactionField.sources,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should handle different chain IDs and addresses correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n chainId: 137,\n address: \"0xdeadbeef\",\n challenge: \"custom-challenge\",\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result = await trustedNameContextFieldLoader.loadField(customField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: 137,\n address: \"0xdeadbeef\",\n challenge: \"custom-challenge\",\n types: mockTransactionField.types,\n sources: mockTransactionField.sources,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should handle different types and sources correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n types: [\"wallet\", \"exchange\"],\n sources: [\"coingecko\", \"1inch\"],\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result = await trustedNameContextFieldLoader.loadField(customField);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: [\"wallet\", \"exchange\"],\n sources: [\"coingecko\", \"1inch\"],\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should preserve error message from trusted name data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Left(specificError));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty trusted name payload\", async () => {\n // GIVEN\n const emptyPayload = \"\";\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(emptyPayload));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: emptyPayload,\n });\n });\n\n it(\"should handle empty types and sources arrays\", async () => {\n // GIVEN\n const fieldWithEmptyArrays = {\n ...mockTransactionField,\n types: [],\n sources: [],\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result =\n await trustedNameContextFieldLoader.loadField(fieldWithEmptyArrays);\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: [],\n sources: [],\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n\n it(\"should handle single type and source\", async () => {\n // GIVEN\n const fieldWithSingleElements = {\n ...mockTransactionField,\n types: [\"contract\"],\n sources: [\"ens\"],\n };\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Right(mockTrustedNamePayload));\n\n // WHEN\n const result = await trustedNameContextFieldLoader.loadField(\n fieldWithSingleElements,\n );\n\n // THEN\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: mockTransactionField.chainId,\n address: mockTransactionField.address,\n challenge: mockTransactionField.challenge,\n types: [\"contract\"],\n sources: [\"ens\"],\n });\n expect(result).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: mockTrustedNamePayload,\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,0BAAAC,MAA8B,qCACvC,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,iCAAAC,MAAqC,sDAE9C,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAmD,CACvD,sBAAuB,GAAG,GAAG,EAC7B,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAgC,IAAIF,EACxCC,CACF,EAEME,EACJ,CACE,KAAML,EAAuB,aAC7B,QAAS,EACT,QAAS,qBACT,UAAW,iBACX,MAAO,CAAC,WAAY,OAAO,EAC3B,QAAS,CAAC,SAAU,KAAK,CAC3B,EAEIM,EAAyB,qBAE/B,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,GAAG,kDAAmD,IAAM,CAE1D,MAAMC,EAAa,CACjB,KAAMP,EAAuB,aAC7B,QAAS,EACT,QAAS,qBACT,UAAW,iBACX,MAAO,CAAC,WAAY,OAAO,EAC3B,QAAS,CAAC,SAAU,KAAK,CAC3B,EAGA,OAAOI,EAA8B,UAAUG,CAAU,CAAC,EAAE,KAAK,EAAI,CACvE,CAAC,EAED,SAAS,yCAA0C,IAAM,CACvD,MAAMC,EAAgB,CACpB,CAAE,KAAM,OAAQ,MAAO,IAAK,EAC5B,CAAE,KAAM,YAAa,MAAO,MAAU,EACtC,CAAE,KAAM,SAAU,MAAO,SAAU,EACnC,CAAE,KAAM,SAAU,MAAO,GAAI,EAC7B,CAAE,KAAM,UAAW,MAAO,EAAK,EAC/B,CAAE,KAAM,QAAS,MAAO,CAAC,CAAE,EAC3B,CAAE,KAAM,eAAgB,MAAO,CAAC,CAAE,EAClC,CACE,KAAM,sBACN,MAAO,CACL,QAAS,EACT,Q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,KAAMV,EAAqB,aAC3B,QAASK,CACX,CAAC,CACH,CAAC,EAED,GAAG,uCAAwC,SAAY,CAErD,MAAMU,EAA0B,CAC9B,GAAGX,EACH,MAAO,CAAC,UAAU,EAClB,QAAS,CAAC,KAAK,CACjB,EACA,GAAG,MACDF,EACA,uBACF,EAAE,kBAAkBJ,EAAMO,CAAsB,CAAC,EAGjD,MAAMK,EAAS,MAAMP,EAA8B,UACjDY,CACF,EAGA,OACEb,EAA0B,qBAC5B,EAAE,qBAAqB,CACrB,QAASE,EAAqB,QAC9B,QAASA,EAAqB,QAC9B,UAAWA,EAAqB,UAChC,MAAO,CAAC,UAAU,EAClB,QAAS,CAAC,KAAK,CACjB,CAAC,EACD,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,aAC3B,QAASK,CACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ContextFieldLoaderKind", "ClearSignContextType", "TrustedNameContextFieldLoader", "mockTrustedNameDataSource", "trustedNameContextFieldLoader", "mockTransactionField", "mockTrustedNamePayload", "validField", "invalidFields", "value", "error", "result", "customField", "specificError", "emptyPayload", "fieldWithEmptyArrays", "fieldWithSingleElements"]
7
7
  }