@ledgerhq/device-signer-kit-ethereum 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +59 -1
  2. package/lib/cjs/api/SignerEth.js +1 -1
  3. package/lib/cjs/api/SignerEth.js.map +1 -1
  4. package/lib/cjs/api/SignerEthBuilder.test.js +1 -1
  5. package/lib/cjs/api/SignerEthBuilder.test.js.map +2 -2
  6. package/lib/cjs/api/app-binder/VerifySafeAddressDeviceActionTypes.js +2 -0
  7. package/lib/cjs/api/app-binder/VerifySafeAddressDeviceActionTypes.js.map +7 -0
  8. package/lib/cjs/api/model/SafeAddressOptions.js +2 -0
  9. package/lib/cjs/api/model/SafeAddressOptions.js.map +7 -0
  10. package/lib/cjs/internal/DefaultSignerEth.js +1 -1
  11. package/lib/cjs/internal/DefaultSignerEth.js.map +3 -3
  12. package/lib/cjs/internal/app-binder/EthAppBinder.js +1 -1
  13. package/lib/cjs/internal/app-binder/EthAppBinder.js.map +3 -3
  14. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.js +2 -0
  15. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.js.map +7 -0
  16. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.test.js +2 -0
  17. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.test.js.map +7 -0
  18. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  19. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  20. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js +2 -0
  21. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js.map +7 -0
  22. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js +2 -0
  23. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js.map +7 -0
  24. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js +1 -1
  25. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  26. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  27. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  28. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.js +2 -0
  29. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.js.map +7 -0
  30. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.test.js +2 -0
  31. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.test.js.map +7 -0
  32. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  33. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
  34. package/lib/cjs/internal/app-binder/task/ProvideContextTask.js +2 -0
  35. package/lib/cjs/internal/app-binder/task/ProvideContextTask.js.map +7 -0
  36. package/lib/cjs/internal/app-binder/task/ProvideContextTask.test.js +2 -0
  37. package/lib/cjs/internal/app-binder/task/ProvideContextTask.test.js.map +7 -0
  38. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  39. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  40. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.js +2 -0
  41. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.js.map +7 -0
  42. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.test.js +2 -0
  43. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.test.js.map +7 -0
  44. package/lib/cjs/internal/di.js +1 -1
  45. package/lib/cjs/internal/di.js.map +3 -3
  46. package/lib/cjs/internal/safe/di/safeModule.js +2 -0
  47. package/lib/cjs/internal/safe/di/safeModule.js.map +7 -0
  48. package/lib/cjs/internal/safe/di/safeModule.test.js +2 -0
  49. package/lib/cjs/internal/safe/di/safeModule.test.js.map +7 -0
  50. package/lib/cjs/internal/safe/di/safeTypes.js +2 -0
  51. package/lib/cjs/internal/safe/di/safeTypes.js.map +7 -0
  52. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.js +2 -0
  53. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.js.map +7 -0
  54. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.test.js +2 -0
  55. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.test.js.map +7 -0
  56. package/lib/cjs/package.json +2 -2
  57. package/lib/esm/api/SignerEthBuilder.test.js +1 -1
  58. package/lib/esm/api/SignerEthBuilder.test.js.map +2 -2
  59. package/lib/esm/api/app-binder/VerifySafeAddressDeviceActionTypes.js +2 -0
  60. package/lib/esm/api/app-binder/VerifySafeAddressDeviceActionTypes.js.map +7 -0
  61. package/lib/esm/api/model/SafeAddressOptions.js +1 -0
  62. package/lib/esm/api/model/SafeAddressOptions.js.map +7 -0
  63. package/lib/esm/internal/DefaultSignerEth.js +1 -1
  64. package/lib/esm/internal/DefaultSignerEth.js.map +3 -3
  65. package/lib/esm/internal/app-binder/EthAppBinder.js +1 -1
  66. package/lib/esm/internal/app-binder/EthAppBinder.js.map +3 -3
  67. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.js +2 -0
  68. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.js.map +7 -0
  69. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.test.js +2 -0
  70. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.test.js.map +7 -0
  71. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  72. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  73. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js +2 -0
  74. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js.map +7 -0
  75. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js +2 -0
  76. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js.map +7 -0
  77. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
  78. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  79. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  80. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +3 -3
  81. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.js +2 -0
  82. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.js.map +7 -0
  83. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.test.js +2 -0
  84. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.test.js.map +7 -0
  85. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  86. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
  87. package/lib/esm/internal/app-binder/task/ProvideContextTask.js +2 -0
  88. package/lib/esm/internal/app-binder/task/ProvideContextTask.js.map +7 -0
  89. package/lib/esm/internal/app-binder/task/ProvideContextTask.test.js +2 -0
  90. package/lib/esm/internal/app-binder/task/ProvideContextTask.test.js.map +7 -0
  91. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  92. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  93. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.js +2 -0
  94. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.js.map +7 -0
  95. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.test.js +2 -0
  96. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.test.js.map +7 -0
  97. package/lib/esm/internal/di.js +1 -1
  98. package/lib/esm/internal/di.js.map +3 -3
  99. package/lib/esm/internal/safe/di/safeModule.js +2 -0
  100. package/lib/esm/internal/safe/di/safeModule.js.map +7 -0
  101. package/lib/esm/internal/safe/di/safeModule.test.js +2 -0
  102. package/lib/esm/internal/safe/di/safeModule.test.js.map +7 -0
  103. package/lib/esm/internal/safe/di/safeTypes.js +2 -0
  104. package/lib/esm/internal/safe/di/safeTypes.js.map +7 -0
  105. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.js +2 -0
  106. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.js.map +7 -0
  107. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.test.js +2 -0
  108. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.test.js.map +7 -0
  109. package/lib/esm/package.json +2 -2
  110. package/lib/types/api/SignerEth.d.ts +3 -0
  111. package/lib/types/api/SignerEth.d.ts.map +1 -1
  112. package/lib/types/api/app-binder/VerifySafeAddressDeviceActionTypes.d.ts +30 -0
  113. package/lib/types/api/app-binder/VerifySafeAddressDeviceActionTypes.d.ts.map +1 -0
  114. package/lib/types/api/model/SafeAddressOptions.d.ts +5 -0
  115. package/lib/types/api/model/SafeAddressOptions.d.ts.map +1 -0
  116. package/lib/types/internal/DefaultSignerEth.d.ts +3 -0
  117. package/lib/types/internal/DefaultSignerEth.d.ts.map +1 -1
  118. package/lib/types/internal/app-binder/EthAppBinder.d.ts +6 -0
  119. package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
  120. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.d.ts +34 -0
  121. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.d.ts.map +1 -0
  122. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.test.d.ts +2 -0
  123. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.test.d.ts.map +1 -0
  124. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +3 -3
  125. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  126. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.d.ts +20 -0
  127. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.d.ts.map +1 -0
  128. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.d.ts +2 -0
  129. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.d.ts.map +1 -0
  130. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts +3 -1
  131. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
  132. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.d.ts +19 -0
  133. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.d.ts.map +1 -0
  134. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.test.d.ts +2 -0
  135. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.test.d.ts.map +1 -0
  136. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  137. package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts +22 -0
  138. package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts.map +1 -0
  139. package/lib/types/internal/app-binder/task/ProvideContextTask.test.d.ts +2 -0
  140. package/lib/types/internal/app-binder/task/ProvideContextTask.test.d.ts.map +1 -0
  141. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +2 -2
  142. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  143. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.d.ts +36 -0
  144. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.d.ts.map +1 -0
  145. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.test.d.ts +2 -0
  146. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.test.d.ts.map +1 -0
  147. package/lib/types/internal/di.d.ts.map +1 -1
  148. package/lib/types/internal/safe/di/safeModule.d.ts +3 -0
  149. package/lib/types/internal/safe/di/safeModule.d.ts.map +1 -0
  150. package/lib/types/internal/safe/di/safeModule.test.d.ts +2 -0
  151. package/lib/types/internal/safe/di/safeModule.test.d.ts.map +1 -0
  152. package/lib/types/internal/safe/di/safeTypes.d.ts +4 -0
  153. package/lib/types/internal/safe/di/safeTypes.d.ts.map +1 -0
  154. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.d.ts +9 -0
  155. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.d.ts.map +1 -0
  156. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.test.d.ts +2 -0
  157. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.test.d.ts.map +1 -0
  158. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  159. package/package.json +6 -6
  160. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +0 -2
  161. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +0 -7
  162. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +0 -2
  163. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +0 -7
  164. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +0 -2
  165. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +0 -7
  166. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +0 -2
  167. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +0 -7
  168. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +0 -44
  169. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +0 -1
  170. package/lib/types/internal/app-binder/task/ProvideContextsTask.test.d.ts +0 -2
  171. package/lib/types/internal/app-binder/task/ProvideContextsTask.test.d.ts.map +0 -1
@@ -0,0 +1,2 @@
1
+ "use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var x=(s,t)=>{for(var i in t)u(s,i,{get:t[i],enumerable:!0})},C=(s,t,i,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of l(t))!y.call(s,e)&&e!==i&&u(s,e,{get:()=>t[e],enumerable:!(d=f(t,e))||d.enumerable});return s};var D=s=>C(u({},"__esModule",{value:!0}),s);var v={};x(v,{VerifySafeAddressDeviceAction:()=>m});module.exports=D(v);var n=require("@ledgerhq/device-management-kit"),o=require("purify-ts"),r=require("xstate"),p=require("../../../../api/app-binder/VerifySafeAddressDeviceActionTypes"),A=require("../../../app-binder/task/BuildSafeAddressContextTask"),S=require("../../../app-binder/task/ProvideContextTask");class m extends n.XStateDeviceAction{makeStateMachine(t){const{buildSafeAddressContexts:i,provideContexts:d}=this.extractDependencies(t);return(0,r.setup)({types:{input:{},context:{},output:{}},actors:{openAppStateMachine:new n.OpenAppDeviceAction({input:{appName:"Ethereum"}}).makeStateMachine(t),buildSafeAddressContexts:(0,r.fromPromise)(i),provideContexts:(0,r.fromPromise)(d)},guards:{noInternalError:({context:e})=>e._internalState.error===null,skipOpenApp:({context:e})=>!!e.input.options.skipOpenApp},actions:{assignErrorFromEvent:(0,r.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"VerifySafeAddressDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:n.UserInteractionRequired.None,step:p.VerifySafeAddressDAStep.OPEN_APP},_internalState:{error:null,contexts:[]}}),states:{InitialState:{always:[{target:"BuildSafeAddressContexts",guard:"skipOpenApp"},"OpenAppDeviceAction"]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",input:{appName:"Ethereum"},src:"openAppStateMachine",onSnapshot:{actions:(0,r.assign)({intermediateValue:e=>({...e.event.snapshot.context.intermediateValue,step:p.VerifySafeAddressDAStep.OPEN_APP})})},onDone:{actions:(0,r.assign)({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:a=>({...e.context._internalState,error:a})})}),target:"CheckOpenAppDeviceActionResult"}}},CheckOpenAppDeviceActionResult:{always:[{target:"BuildSafeAddressContexts",guard:"noInternalError"},"Error"]},BuildSafeAddressContexts:{entry:(0,r.assign)({intermediateValue:{requiredUserInteraction:n.UserInteractionRequired.None,step:p.VerifySafeAddressDAStep.BUILD_CONTEXTS}}),invoke:{id:"buildSafeAddressContexts",src:"buildSafeAddressContexts",input:({context:e})=>({contextModule:e.input.contextModule,safeContractAddress:e.input.safeContractAddress,options:e.input.options,deviceModelId:t.getDeviceModel().id}),onDone:{target:"ProvideContexts",actions:[(0,r.assign)({_internalState:({event:e,context:a})=>({...a._internalState,contexts:e.output.clearSignContexts})})]},onError:{target:"Error",actions:"assignErrorFromEvent"}}},ProvideContexts:{entry:(0,r.assign)({intermediateValue:{requiredUserInteraction:n.UserInteractionRequired.None,step:p.VerifySafeAddressDAStep.VERIFY_SAFE_ADDRESS}}),invoke:{id:"provideContexts",src:"provideContexts",input:({context:e})=>({contexts:e._internalState.contexts}),onDone:{target:"ProvideContextsResultCheck",actions:[(0,r.assign)({_internalState:({event:e,context:a})=>e.output.isLeft()?{...a._internalState,error:e.output.extract()}:{...a._internalState,error:null}})]},onError:{target:"Error",actions:"assignErrorFromEvent"}}},ProvideContextsResultCheck:{always:[{guard:"noInternalError",target:"Success"},{target:"Error"}]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>e._internalState.error?(0,o.Left)(e._internalState.error):(0,o.Right)(void 0)})}extractDependencies(t){return{provideContexts:async e=>{for(const a of e.input.contexts){const c=await new S.ProvideContextTask(t,{context:a}).run();if(!(0,n.isSuccessCommandResult)(c))return(0,o.Left)(c.error)}return(0,o.Right)(void 0)},buildSafeAddressContexts:async e=>new A.BuildSafeAddressContextTask(t,e.input).run()}}}0&&(module.exports={VerifySafeAddressDeviceAction});
2
+ //# sourceMappingURL=VerifySafeAddress.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.ts"],
4
+ "sourcesContent": ["import { type ClearSignContextSuccess } from \"@ledgerhq/context-module\";\nimport {\n type DeviceActionStateMachine,\n type InternalApi,\n isSuccessCommandResult,\n OpenAppDeviceAction,\n type StateMachineTypes,\n UserInteractionRequired,\n XStateDeviceAction,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type VerifySafeAddressDAError,\n type VerifySafeAddressDAInput,\n type VerifySafeAddressDAIntermediateValue,\n type VerifySafeAddressDAInternalState,\n type VerifySafeAddressDAOutput,\n VerifySafeAddressDAStep,\n} from \"@api/app-binder/VerifySafeAddressDeviceActionTypes\";\nimport {\n BuildSafeAddressContextTask,\n type BuildSafeAddressContextTaskArgs,\n type BuildSafeAddressContextTaskResult,\n} from \"@internal/app-binder/task/BuildSafeAddressContextTask\";\nimport { ProvideContextTask } from \"@internal/app-binder/task/ProvideContextTask\";\n\nexport type MachineDependencies = {\n readonly buildSafeAddressContexts: (arg0: {\n input: BuildSafeAddressContextTaskArgs;\n }) => Promise<BuildSafeAddressContextTaskResult>;\n readonly provideContexts: (arg0: {\n input: {\n contexts: ClearSignContextSuccess[];\n };\n }) => Promise<Either<VerifySafeAddressDAError, void>>;\n};\n\nexport class VerifySafeAddressDeviceAction extends XStateDeviceAction<\n VerifySafeAddressDAOutput,\n VerifySafeAddressDAInput,\n VerifySafeAddressDAError,\n VerifySafeAddressDAIntermediateValue,\n VerifySafeAddressDAInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n VerifySafeAddressDAOutput,\n VerifySafeAddressDAInput,\n VerifySafeAddressDAError,\n VerifySafeAddressDAIntermediateValue,\n VerifySafeAddressDAInternalState\n > {\n type types = StateMachineTypes<\n VerifySafeAddressDAOutput,\n VerifySafeAddressDAInput,\n VerifySafeAddressDAError,\n VerifySafeAddressDAIntermediateValue,\n VerifySafeAddressDAInternalState\n >;\n\n const { buildSafeAddressContexts, provideContexts } =\n this.extractDependencies(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n openAppStateMachine: new OpenAppDeviceAction({\n input: { appName: \"Ethereum\" },\n }).makeStateMachine(internalApi),\n buildSafeAddressContexts: fromPromise(buildSafeAddressContexts),\n provideContexts: fromPromise(provideContexts),\n },\n guards: {\n noInternalError: ({ context }) => context._internalState.error === null,\n skipOpenApp: ({ context }) => !!context.input.options.skipOpenApp,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QGUCWUB2AVATgQw1jwGMAXVAewwBEwA3VYsAQTMowDoBJDVcvADbJSeUmADEAbQAMAXUSgADhVh92CkAA9EARgDsAZg4AOACzGAnAFYDNgGxXpF6ToA0IAJ67TOgEwcDHTsLCz9pQN9bAF8o9zRMXAIiNipaBiZWcipuXn4hETEpHXkkEGVVLIwNbQR9IzNLG3tHZzdPXV87aQ5I5ztfSON+zpi49Gx8QhJKtMYWFM4AeUUwDGZFRVmMhfEIKjAOVAw6CgBrA4oVtY3hUTAAWRIACyOwGRKlFTUqasQ9RxMVjMdgcdj0xnBvncXlqkTsHAsQxcnVMvmM4TsoxA8QmSWm7C280qHAAwk8wMRTstVutNvQ5pl2AAlOAAVwEpCkcg05W+VVKNR0gW6IOsoWMfgMdmhHRBHActisFnMMqCmNi2PGiSmC0JjOyZIpVKutINCxZsHZnMkxR5X0qv1qwsVwRVOglcJlcoQEo4ns9pmkQL00mCFgMWJxuuSM3p22JAHEwKRaSSqAAzdC7faHY5nA4wNMbDMYbNQd4OirqAW6CVWDhWPR2fR2Yy+Fu+UwGX1C4zGHoGcPSDuGCx6HTRnWTOMEhNE9gcFMlxRliviMA4HAUHAcRQCUSZ3c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UOybIA4YAIwDDCehVCCfDgWoHBYZecplXSWUovC1u-2AjlpgiYyIicl6St4SXvI7oX7RzWCDFhbLxJkCsmIEwWAGm8Fab-EdiqtFfT_HxgOd0TsQMdjlVEIAA */\n id: \"VerifySafeAddressDeviceAction\",\n initial: \"InitialState\",\n context: ({ input }) => {\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: VerifySafeAddressDAStep.OPEN_APP,\n },\n _internalState: {\n error: null,\n contexts: [],\n },\n };\n },\n states: {\n InitialState: {\n always: [\n {\n target: \"BuildSafeAddressContexts\",\n guard: \"skipOpenApp\",\n },\n \"OpenAppDeviceAction\",\n ],\n },\n OpenAppDeviceAction: {\n invoke: {\n id: \"openAppStateMachine\",\n input: {\n appName: \"Ethereum\",\n },\n src: \"openAppStateMachine\",\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.event.snapshot.context.intermediateValue,\n step: VerifySafeAddressDAStep.OPEN_APP,\n }),\n }),\n },\n onDone: {\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<VerifySafeAddressDAInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n );\n },\n }),\n target: \"CheckOpenAppDeviceActionResult\",\n },\n },\n },\n CheckOpenAppDeviceActionResult: {\n always: [\n {\n target: \"BuildSafeAddressContexts\",\n guard: \"noInternalError\",\n },\n \"Error\",\n ],\n },\n BuildSafeAddressContexts: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: VerifySafeAddressDAStep.BUILD_CONTEXTS,\n },\n }),\n invoke: {\n id: \"buildSafeAddressContexts\",\n src: \"buildSafeAddressContexts\",\n input: ({ context }) => ({\n contextModule: context.input.contextModule,\n safeContractAddress: context.input.safeContractAddress,\n options: context.input.options,\n deviceModelId: internalApi.getDeviceModel().id,\n }),\n onDone: {\n target: \"ProvideContexts\",\n actions: [\n assign({\n _internalState: ({ event, context }) => ({\n ...context._internalState,\n contexts: event.output.clearSignContexts,\n }),\n }),\n ],\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ProvideContexts: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: VerifySafeAddressDAStep.VERIFY_SAFE_ADDRESS,\n },\n }),\n invoke: {\n id: \"provideContexts\",\n src: \"provideContexts\",\n input: ({ context }) => ({\n contexts: context._internalState\n .contexts as ClearSignContextSuccess[],\n }),\n onDone: {\n target: \"ProvideContextsResultCheck\",\n actions: [\n assign({\n _internalState: ({ event, context }) => {\n if (event.output.isLeft()) {\n return {\n ...context._internalState,\n error: event.output.extract(),\n };\n }\n\n return {\n ...context._internalState,\n error: null,\n };\n },\n }),\n ],\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ProvideContextsResultCheck: {\n always: [\n { guard: \"noInternalError\", target: \"Success\" },\n { target: \"Error\" },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error\n ? Left(context._internalState.error)\n : Right(void 0),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const buildSafeAddressContexts = async (arg0: {\n input: BuildSafeAddressContextTaskArgs;\n }) => new BuildSafeAddressContextTask(internalApi, arg0.input).run();\n\n const provideContexts = async (arg0: {\n input: {\n contexts: ClearSignContextSuccess[];\n };\n }) => {\n for (const context of arg0.input.contexts) {\n const res = await new ProvideContextTask(internalApi, {\n context,\n }).run();\n\n if (!isSuccessCommandResult(res)) {\n return Left(res.error);\n }\n }\n return Right(void 0);\n };\n\n return {\n provideContexts,\n buildSafeAddressContexts,\n };\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAQO,2CACPC,EAAyC,qBACzCC,EAA2C,kBAE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,GAAGJ,EAAQ,eACX,MAAO,IACT,CAEJ,CAAC,CACH,CACF,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,2BAA4B,CAC1B,OAAQ,CACN,CAAE,MAAO,kBAAmB,OAAQ,SAAU,EAC9C,CAAE,OAAQ,OAAQ,CACpB,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAAQ,CAAC,CAAE,QAAAA,CAAQ,IACjBA,EAAQ,eAAe,SACnB,QAAKA,EAAQ,eAAe,KAAK,KACjC,SAAM,MAAM,CACpB,CAAC,CACH,CAEA,oBAAoBH,EAA+C,CAsBjE,MAAO,CACL,gBAlBsB,MAAOQ,GAIzB,CACJ,UAAWL,KAAWK,EAAK,MAAM,SAAU,CACzC,MAAMC,EAAM,MAAM,IAAI,qBAAmBT,EAAa,CACpD,QAAAG,CACF,CAAC,EAAE,IAAI,EAEP,GAAI,IAAC,0BAAuBM,CAAG,EAC7B,SAAO,QAAKA,EAAI,KAAK,CAEzB,CACA,SAAO,SAAM,MAAM,CACrB,EAIE,yBAvB+B,MAAOD,GAElC,IAAI,8BAA4BR,EAAaQ,EAAK,KAAK,EAAE,IAAI,CAsBnE,CACF,CACF",
6
+ "names": ["VerifySafeAddress_exports", "__export", "VerifySafeAddressDeviceAction", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_xstate", "import_VerifySafeAddressDeviceActionTypes", "import_BuildSafeAddressContextTask", "import_ProvideContextTask", "internalApi", "buildSafeAddressContexts", "provideContexts", "context", "_", "input", "error", "event", "arg0", "res"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var S=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),A=require("purify-ts"),v=require("rxjs"),E=require("../../../../api/app-binder/VerifySafeAddressDeviceActionTypes"),w=require("../../../app-binder/device-action/__test-utils__/makeInternalApi"),d=require("../../../app-binder/device-action/__test-utils__/setupOpenAppDAMock"),C=require("../../../app-binder/device-action/__test-utils__/testDeviceActionUntilStep"),l=require("./VerifySafeAddress");vi.mock("@ledgerhq/device-management-kit",async o=>({...await o(),OpenAppDeviceAction:vi.fn(()=>({makeStateMachine:vi.fn()}))}));describe("VerifySafeAddressDeviceAction",()=>{let o;const s={getContexts:vi.fn()},r=vi.fn(),x=vi.fn();function u(){return{buildSafeAddressContexts:r,provideContexts:x}}const a=(0,w.makeDeviceActionInternalApiMock)(),c="0x1234567890123456789012345678901234567890",i=1,m={type:S.ClearSignContextType.SAFE,payload:"safe_payload"},y={type:S.ClearSignContextType.SIGNER,payload:"signer_payload"};function p(e){a.getDeviceModel.mockReturnValue({id:e}),a.getDeviceSessionState.mockReturnValue({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e,isSecureConnectionAllowed:!1})}const k=(e,n)=>{if(e[n]?.status!==t.DeviceActionStatus.Pending)throw new Error(`Step ${n} is not pending: ${JSON.stringify(e[n])}`);return e[n]};describe("Happy path",()=>{describe("should verify safe address",()=>{beforeEach(()=>{vi.resetAllMocks(),(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX),r.mockResolvedValueOnce({clearSignContexts:[m,y]}),x.mockResolvedValueOnce((0,A.Right)(void 0));const e=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(e,"extractDependencies").mockReturnValue(u()),o=e._execute(a).observable}),it("should open the app",async()=>{const{steps:e}=await(0,C.executeUntilStep)(0,o);expect(k(e,0).intermediateValue.step).toBe(E.VerifySafeAddressDAStep.OPEN_APP)}),it("should confirm open app",async()=>{const{steps:e}=await(0,C.executeUntilStep)(1,o);expect(k(e,1).intermediateValue.requiredUserInteraction).toBe(t.UserInteractionRequired.ConfirmOpenApp)}),it("should build safe address contexts",async()=>{const{steps:e}=await(0,C.executeUntilStep)(2,o);expect(k(e,2).intermediateValue.step).toBe(E.VerifySafeAddressDAStep.BUILD_CONTEXTS),expect(r).toHaveBeenCalledWith(expect.objectContaining({input:{contextModule:s,safeContractAddress:c,options:{chainId:i},deviceModelId:t.DeviceModelId.FLEX}}))}),it("should provide contexts (verify safe address)",async()=>{const{steps:e}=await(0,C.executeUntilStep)(3,o);expect(k(e,3).intermediateValue.step).toBe(E.VerifySafeAddressDAStep.VERIFY_SAFE_ADDRESS),expect(x).toHaveBeenCalledWith(expect.objectContaining({input:{contexts:[m,y]}}))}),it("should complete successfully",async()=>{const e=await(0,v.lastValueFrom)(o);expect(e).toEqual({status:t.DeviceActionStatus.Completed,output:void 0})})}),describe("should skip open app",()=>{beforeEach(()=>{vi.resetAllMocks(),(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX);const e=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i,skipOpenApp:!0},contextModule:s}});r.mockResolvedValueOnce({clearSignContexts:[m,y]}),x.mockResolvedValueOnce((0,A.Right)(void 0)),vi.spyOn(e,"extractDependencies").mockReturnValue(u()),o=e._execute(a).observable}),it("should skip open app and build contexts directly",async()=>{const{steps:e}=await(0,C.executeUntilStep)(0,o);expect(k(e,0).intermediateValue.step).toBe(E.VerifySafeAddressDAStep.BUILD_CONTEXTS)})}),describe("should work with different device models",()=>{it.each([[t.DeviceModelId.NANO_S,"Nano S"],[t.DeviceModelId.NANO_SP,"Nano S Plus"],[t.DeviceModelId.NANO_X,"Nano X"],[t.DeviceModelId.FLEX,"Flex"],[t.DeviceModelId.STAX,"Stax"]])("should verify safe address on %s device",async(e,n)=>{vi.resetAllMocks(),(0,d.setupOpenAppDAMock)(),p(e),r.mockResolvedValueOnce({clearSignContexts:[m,y]}),x.mockResolvedValueOnce((0,A.Right)(void 0));const f=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i,skipOpenApp:!0},contextModule:s}});vi.spyOn(f,"extractDependencies").mockReturnValue(u()),o=f._execute(a).observable;const h=await(0,v.lastValueFrom)(o);expect(h).toEqual({status:t.DeviceActionStatus.Completed,output:void 0}),expect(r).toHaveBeenCalledWith(expect.objectContaining({input:expect.objectContaining({deviceModelId:e})}))})}),describe("should work with contexts with certificates",()=>{beforeEach(()=>{vi.resetAllMocks(),(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX);const e={type:S.ClearSignContextType.SAFE,payload:"safe_payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},n={type:S.ClearSignContextType.SIGNER,payload:"signer_payload",certificate:{keyUsageNumber:2,payload:new Uint8Array([4,5,6])}};r.mockResolvedValueOnce({clearSignContexts:[e,n]}),x.mockResolvedValueOnce((0,A.Right)(void 0));const f=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i,skipOpenApp:!0},contextModule:s}});vi.spyOn(f,"extractDependencies").mockReturnValue(u()),o=f._execute(a).observable}),it("should handle contexts with certificates",async()=>{const e=await(0,v.lastValueFrom)(o);expect(e).toEqual({status:t.DeviceActionStatus.Completed,output:void 0})})})}),describe("Error cases",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should return an error if the open app throws an error",async()=>{(0,d.setupOpenAppDAMock)(new Error("Open app failed")),p(t.DeviceModelId.FLEX);const e=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(e,"extractDependencies").mockReturnValue(u()),o=e._execute(a).observable;const n=await(0,v.lastValueFrom)(o);expect(n).toEqual({status:t.DeviceActionStatus.Error,error:new Error("Open app failed")})}),it("should return an error if buildSafeAddressContexts throws an error",async()=>{(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX),r.mockRejectedValueOnce(new Error("Failed to build contexts"));const e=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(e,"extractDependencies").mockReturnValue(u()),o=e._execute(a).observable;const n=await(0,v.lastValueFrom)(o);expect(n).toEqual({status:t.DeviceActionStatus.Error,error:new Error("Failed to build contexts")})}),it("should return an error if provideContexts returns Left (error)",async()=>{(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX),r.mockResolvedValueOnce({clearSignContexts:[m,y]});const e=new t.InvalidStatusWordError("Failed to provide context");x.mockResolvedValueOnce((0,A.Left)(e));const n=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(n,"extractDependencies").mockReturnValue(u()),o=n._execute(a).observable;const f=await(0,v.lastValueFrom)(o);expect(f).toEqual({status:t.DeviceActionStatus.Error,error:e})}),it("should return an error if provideContexts throws an error",async()=>{(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX),r.mockResolvedValueOnce({clearSignContexts:[m,y]}),x.mockRejectedValueOnce(new Error("Provide contexts failed"));const e=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(e,"extractDependencies").mockReturnValue(u()),o=e._execute(a).observable;const n=await(0,v.lastValueFrom)(o);expect(n).toEqual({status:t.DeviceActionStatus.Error,error:new Error("Provide contexts failed")})}),it("should return an error when buildSafeAddressContexts returns invalid data",async()=>{(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX),r.mockRejectedValueOnce(new Error("Invalid safe address contexts"));const e=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(e,"extractDependencies").mockReturnValue(u()),o=e._execute(a).observable;const n=await(0,v.lastValueFrom)(o);expect(n).toEqual({status:t.DeviceActionStatus.Error,error:new Error("Invalid safe address contexts")})}),it("should handle user rejection during provide contexts",async()=>{(0,d.setupOpenAppDAMock)(),p(t.DeviceModelId.FLEX),r.mockResolvedValueOnce({clearSignContexts:[m,y]});const e=new t.InvalidStatusWordError("User rejected");e.errorCode="6985",x.mockResolvedValueOnce((0,A.Left)(e));const n=new l.VerifySafeAddressDeviceAction({input:{safeContractAddress:c,options:{chainId:i},contextModule:s}});vi.spyOn(n,"extractDependencies").mockReturnValue(u()),o=n._execute(a).observable;const f=await(0,v.lastValueFrom)(o);expect(f).toEqual({status:t.DeviceActionStatus.Error,error:e})})})});
2
+ //# sourceMappingURL=VerifySafeAddress.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.ts"],
4
+ "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: 0 */\nimport {\n ClearSignContextType,\n type ContextModule,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceActionState,\n DeviceActionStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n TransportDeviceModel,\n UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { lastValueFrom, Observable } from \"rxjs\";\n\nimport {\n VerifySafeAddressDAError,\n VerifySafeAddressDAIntermediateValue,\n type VerifySafeAddressDAState,\n VerifySafeAddressDAStep,\n} from \"@api/app-binder/VerifySafeAddressDeviceActionTypes\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { setupOpenAppDAMock } from \"@internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock\";\nimport { executeUntilStep } from \"@internal/app-binder/device-action/__test-utils__/testDeviceActionUntilStep\";\n\nimport { VerifySafeAddressDeviceAction } from \"./VerifySafeAddress\";\n\nvi.mock(\"@ledgerhq/device-management-kit\", async (importOriginal) => {\n const original =\n await importOriginal<typeof import(\"@ledgerhq/device-management-kit\")>();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n});\n\ndescribe(\"VerifySafeAddressDeviceAction\", () => {\n let observable: Observable<\n DeviceActionState<\n void,\n VerifySafeAddressDAError,\n VerifySafeAddressDAIntermediateValue\n >\n >;\n const contextModuleMock = {\n getContexts: vi.fn(),\n };\n const buildSafeAddressContextsMock = vi.fn();\n const provideContextsMock = vi.fn();\n\n function extractDependenciesMock() {\n return {\n buildSafeAddressContexts: buildSafeAddressContextsMock,\n provideContexts: provideContextsMock,\n };\n }\n\n const apiMock = makeDeviceActionInternalApiMock();\n const TEST_SAFE_ADDRESS = \"0x1234567890123456789012345678901234567890\";\n const TEST_CHAIN_ID = 1;\n\n const validSafeContext = {\n type: ClearSignContextType.SAFE,\n payload: \"safe_payload\",\n };\n\n const validSignerContext = {\n type: ClearSignContextType.SIGNER,\n payload: \"signer_payload\",\n };\n\n function setupDeviceModel(deviceModelId: DeviceModelId) {\n apiMock.getDeviceModel.mockReturnValue({\n id: deviceModelId,\n } as unknown as TransportDeviceModel);\n apiMock.getDeviceSessionState.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId,\n isSecureConnectionAllowed: false,\n });\n }\n\n const getStep = (s: Array<VerifySafeAddressDAState>, index: number) => {\n if (s[index]?.status !== DeviceActionStatus.Pending) {\n throw new Error(\n `Step ${index} is not pending: ${JSON.stringify(s[index])}`,\n );\n }\n return s[index];\n };\n\n describe(\"Happy path\", () => {\n describe(\"should verify safe address\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n\n // Mock the dependencies to return some sample data\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n provideContextsMock.mockResolvedValueOnce(Right(void 0));\n\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should open the app\", async () => {\n const { steps } = await executeUntilStep(0, observable);\n expect(getStep(steps, 0).intermediateValue.step).toBe(\n VerifySafeAddressDAStep.OPEN_APP,\n );\n });\n\n it(\"should confirm open app\", async () => {\n const { steps } = await executeUntilStep(1, observable);\n expect(\n getStep(steps, 1).intermediateValue.requiredUserInteraction,\n ).toBe(UserInteractionRequired.ConfirmOpenApp);\n });\n\n it(\"should build safe address contexts\", async () => {\n const { steps } = await executeUntilStep(2, observable);\n expect(getStep(steps, 2).intermediateValue.step).toBe(\n VerifySafeAddressDAStep.BUILD_CONTEXTS,\n );\n expect(buildSafeAddressContextsMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: contextModuleMock as unknown as ContextModule,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n },\n }),\n );\n });\n\n it(\"should provide contexts (verify safe address)\", async () => {\n const { steps } = await executeUntilStep(3, observable);\n expect(getStep(steps, 3).intermediateValue.step).toBe(\n VerifySafeAddressDAStep.VERIFY_SAFE_ADDRESS,\n );\n expect(provideContextsMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contexts: [validSafeContext, validSignerContext],\n },\n }),\n );\n });\n\n it(\"should complete successfully\", async () => {\n const result = await lastValueFrom(observable);\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: void 0,\n });\n });\n });\n\n describe(\"should skip open app\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID, skipOpenApp: true },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n provideContextsMock.mockResolvedValueOnce(Right(void 0));\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should skip open app and build contexts directly\", async () => {\n const { steps } = await executeUntilStep(0, observable);\n\n expect(getStep(steps, 0).intermediateValue.step).toBe(\n VerifySafeAddressDAStep.BUILD_CONTEXTS,\n );\n });\n });\n\n describe(\"should work with different device models\", () => {\n it.each([\n [DeviceModelId.NANO_S, \"Nano S\"],\n [DeviceModelId.NANO_SP, \"Nano S Plus\"],\n [DeviceModelId.NANO_X, \"Nano X\"],\n [DeviceModelId.FLEX, \"Flex\"],\n [DeviceModelId.STAX, \"Stax\"],\n ])(\n \"should verify safe address on %s device\",\n async (deviceModelId, _deviceName) => {\n // GIVEN\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupDeviceModel(deviceModelId);\n\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n provideContextsMock.mockResolvedValueOnce(Right(void 0));\n\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID, skipOpenApp: true },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: void 0,\n });\n expect(buildSafeAddressContextsMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: expect.objectContaining({\n deviceModelId,\n }),\n }),\n );\n },\n );\n });\n\n describe(\"should work with contexts with certificates\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n\n const safeContextWithCert = {\n type: ClearSignContextType.SAFE,\n payload: \"safe_payload\",\n certificate: {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3]),\n },\n };\n\n const signerContextWithCert = {\n type: ClearSignContextType.SIGNER,\n payload: \"signer_payload\",\n certificate: {\n keyUsageNumber: 2,\n payload: new Uint8Array([4, 5, 6]),\n },\n };\n\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [safeContextWithCert, signerContextWithCert],\n });\n provideContextsMock.mockResolvedValueOnce(Right(void 0));\n\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID, skipOpenApp: true },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should handle contexts with certificates\", async () => {\n const result = await lastValueFrom(observable);\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: void 0,\n });\n });\n });\n });\n\n describe(\"Error cases\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an error if the open app throws an error\", async () => {\n // GIVEN\n setupOpenAppDAMock(new Error(\"Open app failed\"));\n setupDeviceModel(DeviceModelId.FLEX);\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Open app failed\"),\n });\n });\n\n it(\"should return an error if buildSafeAddressContexts throws an error\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n buildSafeAddressContextsMock.mockRejectedValueOnce(\n new Error(\"Failed to build contexts\"),\n );\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Failed to build contexts\"),\n });\n });\n\n it(\"should return an error if provideContexts returns Left (error)\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n const provideError = new InvalidStatusWordError(\n \"Failed to provide context\",\n );\n provideContextsMock.mockResolvedValueOnce(Left(provideError));\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: provideError,\n });\n });\n\n it(\"should return an error if provideContexts throws an error\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n provideContextsMock.mockRejectedValueOnce(\n new Error(\"Provide contexts failed\"),\n );\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Provide contexts failed\"),\n });\n });\n\n it(\"should return an error when buildSafeAddressContexts returns invalid data\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n buildSafeAddressContextsMock.mockRejectedValueOnce(\n new Error(\"Invalid safe address contexts\"),\n );\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Invalid safe address contexts\"),\n });\n });\n\n it(\"should handle user rejection during provide contexts\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n setupDeviceModel(DeviceModelId.FLEX);\n buildSafeAddressContextsMock.mockResolvedValueOnce({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n const userRejectionError = new InvalidStatusWordError(\"User rejected\");\n (\n userRejectionError as InvalidStatusWordError & { errorCode: string }\n ).errorCode = \"6985\";\n provideContextsMock.mockResolvedValueOnce(Left(userRejectionError));\n const deviceAction = new VerifySafeAddressDeviceAction({\n input: {\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n contextModule: contextModuleMock as unknown as ContextModule,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: userRejectionError,\n });\n });\n });\n});\n"],
5
+ "mappings": "aACA,IAAAA,EAGO,oCACPC,EASO,2CACPC,EAA4B,qBAC5BC,EAA0C,gBAE1CC,EAKO,8DACPC,EAAgD,6EAChDC,EAAmC,gFACnCC,EAAiC,uFAEjCC,EAA8C,+BAE9C,GAAG,KAAK,kCAAmC,MAAOC,IAGzC,CACL,GAFA,MAAMA,EAAiE,EAGvE,oBAAqB,GAAG,GAAG,KAAO,CAChC,iBAAkB,GAAG,GAAG,CAC1B,EAAE,CACJ,EACD,EAED,SAAS,gCAAiC,IAAM,CAC9C,IAAIC,EAOJ,MAAMC,EAAoB,CACxB,YAAa,GAAG,GAAG,CACrB,EACMC,EAA+B,GAAG,GAAG,EACrCC,EAAsB,GAAG,GAAG,EAElC,SAASC,GAA0B,CACjC,MAAO,CACL,yBAA0BF,EAC1B,gBAAiBC,CACnB,CACF,CAEA,MAAME,KAAU,mCAAgC,EAC1CC,EAAoB,6CACpBC,EAAgB,EAEhBC,EAAmB,CACvB,KAAM,uBAAqB,KAC3B,QAAS,cACX,EAEMC,EAAqB,CACzB,KAAM,uBAAqB,OAC3B,QAAS,gBACX,EAEA,SAASC,EAAiBC,EAA8B,CACtDN,EAAQ,eAAe,gBAAgB,CACrC,GAAIM,CACN,CAAoC,EACpCN,EAAQ,sBAAsB,gBAAgB,CAC5C,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAAM,EACA,0BAA2B,EAC7B,CAAC,CACH,CAEA,MAAMC,EAAU,CAACC,EAAoCC,IAAkB,CACrE,GAAID,EAAEC,CAAK,GAAG,SAAW,qBAAmB,QAC1C,MAAM,IAAI,MACR,QAAQA,CAAK,oBA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MY,EAAS,QAAM,iBAAcjB,CAAU,EAG7C,OAAOiB,CAAM,EAAE,QAAQ,CACrB,OAAQ,qBAAmB,MAC3B,MAAOK,CACT,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_context_module", "import_device_management_kit", "import_purify_ts", "import_rxjs", "import_VerifySafeAddressDeviceActionTypes", "import_makeInternalApi", "import_setupOpenAppDAMock", "import_testDeviceActionUntilStep", "import_VerifySafeAddress", "importOriginal", "observable", "contextModuleMock", "buildSafeAddressContextsMock", "provideContextsMock", "extractDependenciesMock", "apiMock", "TEST_SAFE_ADDRESS", "TEST_CHAIN_ID", "validSafeContext", "validSignerContext", "setupDeviceModel", "deviceModelId", "getStep", "s", "index", "deviceAction", "steps", "result", "_deviceName", "safeContextWithCert", "signerContextWithCert", "provideError", "userRejectionError"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var y=(i,t)=>{for(var n in t)d(i,n,{get:t[n],enumerable:!0})},R=(i,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of E(t))!O.call(i,s)&&s!==n&&d(i,s,{get:()=>t[s],enumerable:!(a=I(t,s))||a.enumerable});return i};var h=i=>R(d({},"__esModule",{value:!0}),i);var m={};y(m,{BuildBaseContexts:()=>f});module.exports=h(m);var e=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),S=require("../../../api/model/ClearSigningType"),u=require("../../app-binder/command/GetChallengeCommand"),T=require("../../app-binder/task/GetWeb3CheckTask"),_=require("../../shared/utils/ApplicationChecker");const A=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,e.ClearSignContextType.ENUM,e.ClearSignContextType.PROXY_INFO];class f{constructor(t,n,a=(s,r)=>new T.GetWeb3CheckTask(s,r)){this._api=t;this._args=n;this.getWeb3ChecksFactory=a}async run(){const{contextModule:t,options:n,appConfig:a,derivationPath:s,transaction:r,subset:N}=this._args,x=r===void 0,C=this._api.getDeviceSessionState();let g;if(C.deviceModelId!==c.DeviceModelId.NANO_S){const o=await this._api.sendCommand(new u.GetChallengeCommand);(0,c.isSuccessCommandResult)(o)&&(g=o.data.challenge)}const p=await t.getContexts({challenge:g,domain:n.domain,deviceModelId:C.deviceModelId,...N},x?A:void 0);if(r&&a.web3ChecksEnabled){const o=(await this.getWeb3ChecksFactory(this._api,{contextModule:t,derivationPath:s,subset:N,transaction:r}).run()).web3Check;o&&p.unshift(o)}const l=p.filter(o=>o.type!==e.ClearSignContextType.ERROR);return this._supportsGenericParser(C,a)&&this._hasValidTransactionInfo(l)?this._getERC7730Contexts(l):this._getBasicContexts(l)}_getERC7730Contexts(t){const n=t.filter(s=>this._isContextNeededForERC7730ClearSigning(s)).sort((s,r)=>this._getContextPriority(s)-this._getContextPriority(r)),a=t.filter(s=>s.type===e.ClearSignContextType.ENUM);return{clearSignContexts:n,clearSignContextsOptional:a,clearSigningType:S.ClearSigningType.EIP7730}}_getBasicContexts(t){return{clearSignContexts:t.filter(a=>this._isContextNeededForBasicClearSigning(a)).sort((a,s)=>this._getContextPriority(a)-this._getContextPriority(s)),clearSignContextsOptional:[],clearSigningType:S.ClearSigningType.BASIC}}_isContextNeededForBasicClearSigning({type:t}){switch(t){case e.ClearSignContextType.WEB3_CHECK:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:return!0;case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:case e.ClearSignContextType.PROXY_INFO:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_isContextNeededForERC7730ClearSigning({type:t}){switch(t){case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.PROXY_INFO:case e.ClearSignContextType.WEB3_CHECK:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:return!0;case e.ClearSignContextType.ENUM:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_hasValidTransactionInfo(t){return t.find(n=>n.type===e.ClearSignContextType.TRANSACTION_INFO)?.certificate!==void 0}_supportsGenericParser(t,n){return new _.ApplicationChecker(t,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}_getContextPriority({type:t}){switch(t){case e.ClearSignContextType.WEB3_CHECK:return 10;case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.PROXY_INFO:return 30;case e.ClearSignContextType.TRANSACTION_INFO:return 50;case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:return 70;default:{const n=t;throw new Error(`Unhandled context type for priority: ${String(n)}`)}}}}0&&(module.exports={BuildBaseContexts});
1
+ "use strict";var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var y=(r,t)=>{for(var n in t)N(r,n,{get:t[n],enumerable:!0})},h=(r,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of R(t))!A.call(r,s)&&s!==n&&N(r,s,{get:()=>t[s],enumerable:!(a=O(t,s))||a.enumerable});return r};var f=r=>h(N({},"__esModule",{value:!0}),r);var F={};y(F,{BASE_CONTEXT_TYPES_FILTER:()=>u,BuildBaseContexts:()=>m,NESTED_CALLDATA_CONTEXT_TYPES_FILTER:()=>I});module.exports=f(F);var e=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),S=require("../../../api/model/ClearSigningType"),E=require("../../app-binder/command/GetChallengeCommand"),_=require("../../app-binder/task/GetWeb3CheckTask"),p=require("../../shared/utils/ApplicationChecker");const I=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,e.ClearSignContextType.ENUM,e.ClearSignContextType.PROXY_INFO],u=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,e.ClearSignContextType.PROXY_INFO,e.ClearSignContextType.WEB3_CHECK,e.ClearSignContextType.DYNAMIC_NETWORK,e.ClearSignContextType.DYNAMIC_NETWORK_ICON,e.ClearSignContextType.ENUM,e.ClearSignContextType.TRUSTED_NAME,e.ClearSignContextType.TOKEN,e.ClearSignContextType.NFT,e.ClearSignContextType.PLUGIN,e.ClearSignContextType.EXTERNAL_PLUGIN];class m{constructor(t,n,a=(s,i)=>new _.GetWeb3CheckTask(s,i)){this._api=t;this._args=n;this.getWeb3ChecksFactory=a}async run(){const{contextModule:t,options:n,appConfig:a,derivationPath:s,transaction:i,subset:T}=this._args,x=i===void 0,C=this._api.getDeviceSessionState();let d;if(C.deviceModelId!==c.DeviceModelId.NANO_S){const o=await this._api.sendCommand(new E.GetChallengeCommand);(0,c.isSuccessCommandResult)(o)&&(d=o.data.challenge)}const g=await t.getContexts({challenge:d,domain:n.domain,deviceModelId:C.deviceModelId,...T},x?I:u);if(i&&a.web3ChecksEnabled){const o=(await this.getWeb3ChecksFactory(this._api,{contextModule:t,derivationPath:s,subset:T,transaction:i}).run()).web3Check;o&&g.unshift(o)}const l=g.filter(o=>o.type!==e.ClearSignContextType.ERROR);return this._supportsGenericParser(C,a)&&this._hasValidTransactionInfo(l)?this._getERC7730Contexts(l):this._getBasicContexts(l)}_getERC7730Contexts(t){const n=t.filter(s=>this._isContextNeededForERC7730ClearSigning(s)).sort((s,i)=>this._getContextPriority(s)-this._getContextPriority(i)),a=t.filter(s=>s.type===e.ClearSignContextType.ENUM);return{clearSignContexts:n,clearSignContextsOptional:a,clearSigningType:S.ClearSigningType.EIP7730}}_getBasicContexts(t){return{clearSignContexts:t.filter(a=>this._isContextNeededForBasicClearSigning(a)).sort((a,s)=>this._getContextPriority(a)-this._getContextPriority(s)),clearSignContextsOptional:[],clearSigningType:S.ClearSigningType.BASIC}}_isContextNeededForBasicClearSigning({type:t}){switch(t){case e.ClearSignContextType.WEB3_CHECK:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:return!0;case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:case e.ClearSignContextType.PROXY_INFO:case e.ClearSignContextType.SAFE:case e.ClearSignContextType.SIGNER:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_isContextNeededForERC7730ClearSigning({type:t}){switch(t){case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.PROXY_INFO:case e.ClearSignContextType.WEB3_CHECK:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:return!0;case e.ClearSignContextType.ENUM:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.SAFE:case e.ClearSignContextType.SIGNER:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_hasValidTransactionInfo(t){return t.find(n=>n.type===e.ClearSignContextType.TRANSACTION_INFO)?.certificate!==void 0}_supportsGenericParser(t,n){return new p.ApplicationChecker(t,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}_getContextPriority({type:t}){switch(t){case e.ClearSignContextType.WEB3_CHECK:return 10;case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.PROXY_INFO:return 30;case e.ClearSignContextType.TRANSACTION_INFO:return 50;case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:return 70;case e.ClearSignContextType.SAFE:case e.ClearSignContextType.SIGNER:return 90;default:{const n=t;throw new Error(`Unhandled context type for priority: ${String(n)}`)}}}}0&&(module.exports={BASE_CONTEXT_TYPES_FILTER,BuildBaseContexts,NESTED_CALLDATA_CONTEXT_TYPES_FILTER});
2
2
  //# sourceMappingURL=BuildBaseContexts.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nconst NESTED_CALLDATA_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.ENUM,\n ClearSignContextType.PROXY_INFO,\n];\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n * @param getWeb3ChecksFactory - The factory for the web3 checks\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const isNestedCallData = transaction === undefined;\n const deviceState = this._api.getDeviceSessionState();\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts(\n {\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n },\n isNestedCallData ? NESTED_CALLDATA_CONTEXT_TYPES_FILTER : undefined,\n );\n\n // Run the web3checks if needed\n if (transaction && appConfig.web3ChecksEnabled) {\n const web3CheckContext = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n if (web3CheckContext) {\n clearSignContexts.unshift(web3CheckContext);\n }\n }\n\n // filter out the error contexts\n const contextsSuccess: ClearSignContextSuccess[] = clearSignContexts.filter(\n (context) => context.type !== ClearSignContextType.ERROR,\n );\n\n if (\n this._supportsGenericParser(deviceState, appConfig) &&\n this._hasValidTransactionInfo(contextsSuccess)\n ) {\n return this._getERC7730Contexts(contextsSuccess);\n } else {\n return this._getBasicContexts(contextsSuccess);\n }\n }\n\n private _getERC7730Contexts(\n contexts: ClearSignContextSuccess[],\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForERC7730ClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n const clearSignContextsOptional: ClearSignContextSuccess[] =\n contexts.filter((context) => context.type === ClearSignContextType.ENUM);\n\n return {\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n };\n }\n\n private _getBasicContexts(\n contexts: ClearSignContextSuccess[],\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForBasicClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n return {\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n };\n }\n\n private _isContextNeededForBasicClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n return true;\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.PROXY_INFO:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _isContextNeededForERC7730ClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.PROXY_INFO:\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n return true;\n case ClearSignContextType.ENUM: // enum is needed but as optional\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _hasValidTransactionInfo(\n contexts: ClearSignContextSuccess[],\n ): boolean {\n return (\n contexts.find(\n (context) => context.type === ClearSignContextType.TRANSACTION_INFO,\n )?.certificate !== undefined\n );\n }\n\n private _supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n\n /**\n * Determines the processing priority of a clear sign context.\n * Lower numbers indicate higher priority (processed first).\n *\n * @param context The clear sign context to get priority for\n * @returns Priority number (lower = higher priority)\n */\n private _getContextPriority({ type }: ClearSignContextSuccess): number {\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n return 10;\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.PROXY_INFO:\n return 30;\n case ClearSignContextType.TRANSACTION_INFO:\n return 50;\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n return 70;\n\n default: {\n const uncoveredType: never = type;\n throw new Error(\n `Unhandled context type for priority: ${String(uncoveredType)}`,\n );\n }\n }\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAEnC,MAAMC,EAA+D,CACnE,uBAAqB,iBACrB,uBAAqB,8BACrB,uBAAqB,KACrB,uBAAqB,UACvB,EAyBO,MAAMR,CAAkB,CAC7B,YACmBS,EACAC,EACAC,EAAuB,CACtCC,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,UAAAJ,EACA,WAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAAwC,CAC5C,KAAM,CACJ,cAAAG,EACA,QAAAC,EACA,UAAAC,EACA,eAAAC,EACA,YAAAC,EACA,OAAAC,CACF,EAAI,KAAK,MACHC,EAAmBF,IAA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AoC,CACrE,OAAQA,EAAM,CACZ,KAAK,uBAAqB,WACxB,MAAO,IACT,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,qBAC1B,KAAK,uBAAqB,WACxB,MAAO,IACT,KAAK,uBAAqB,iBACxB,MAAO,IACT,KAAK,uBAAqB,OAC1B,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,MAC1B,KAAK,uBAAqB,IAC1B,KAAK,uBAAqB,aAC1B,KAAK,uBAAqB,8BAC1B,KAAK,uBAAqB,KACxB,MAAO,IAET,QAAS,CACP,MAAMC,EAAuBD,EAC7B,MAAM,IAAI,MACR,wCAAwC,OAAOC,CAAa,CAAC,EAC/D,CACF,CACF,CACF,CACF",
6
- "names": ["BuildBaseContexts_exports", "__export", "BuildBaseContexts", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "NESTED_CALLDATA_CONTEXT_TYPES_FILTER", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "isNestedCallData", "deviceState", "challenge", "challengeRes", "clearSignContexts", "web3CheckContext", "contextsSuccess", "context", "contexts", "a", "b", "clearSignContextsOptional", "type", "uncoveredType"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport const NESTED_CALLDATA_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.ENUM,\n ClearSignContextType.PROXY_INFO,\n];\n\nexport const BASE_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.WEB3_CHECK,\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ClearSignContextType.ENUM,\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TOKEN,\n ClearSignContextType.NFT,\n ClearSignContextType.PLUGIN,\n ClearSignContextType.EXTERNAL_PLUGIN,\n];\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n * @param getWeb3ChecksFactory - The factory for the web3 checks\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const isNestedCallData = transaction === undefined;\n const deviceState = this._api.getDeviceSessionState();\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts(\n {\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n },\n isNestedCallData\n ? NESTED_CALLDATA_CONTEXT_TYPES_FILTER\n : BASE_CONTEXT_TYPES_FILTER,\n );\n\n // Run the web3checks if needed\n if (transaction && appConfig.web3ChecksEnabled) {\n const web3CheckContext = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n if (web3CheckContext) {\n clearSignContexts.unshift(web3CheckContext);\n }\n }\n\n // filter out the error contexts\n const contextsSuccess: ClearSignContextSuccess[] = clearSignContexts.filter(\n (context) => context.type !== ClearSignContextType.ERROR,\n );\n\n if (\n this._supportsGenericParser(deviceState, appConfig) &&\n this._hasValidTransactionInfo(contextsSuccess)\n ) {\n return this._getERC7730Contexts(contextsSuccess);\n } else {\n return this._getBasicContexts(contextsSuccess);\n }\n }\n\n private _getERC7730Contexts(\n contexts: ClearSignContextSuccess[],\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForERC7730ClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n const clearSignContextsOptional: ClearSignContextSuccess[] =\n contexts.filter((context) => context.type === ClearSignContextType.ENUM);\n\n return {\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n };\n }\n\n private _getBasicContexts(\n contexts: ClearSignContextSuccess[],\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForBasicClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n return {\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n };\n }\n\n private _isContextNeededForBasicClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n return true;\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.PROXY_INFO:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _isContextNeededForERC7730ClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.PROXY_INFO:\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n return true;\n case ClearSignContextType.ENUM: // enum is needed but as optional\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _hasValidTransactionInfo(\n contexts: ClearSignContextSuccess[],\n ): boolean {\n return (\n contexts.find(\n (context) => context.type === ClearSignContextType.TRANSACTION_INFO,\n )?.certificate !== undefined\n );\n }\n\n private _supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n\n /**\n * Determines the processing priority of a clear sign context.\n * Lower numbers indicate higher priority (processed first).\n *\n * @param context The clear sign context to get priority for\n * @returns Priority number (lower = higher priority)\n */\n private _getContextPriority({ type }: ClearSignContextSuccess): number {\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n return 10;\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.PROXY_INFO:\n return 30;\n case ClearSignContextType.TRANSACTION_INFO:\n return 50;\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n return 70;\n\n /* not used here */\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n return 90;\n\n default: {\n const uncoveredType: never = type;\n throw new Error(\n `Unhandled context type for priority: ${String(uncoveredType)}`,\n );\n }\n }\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,sBAAAC,EAAA,yCAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAMO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAE5B,MAAMP,EAA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XT_TYPES_FILTER", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "isNestedCallData", "deviceState", "challenge", "challengeRes", "clearSignContexts", "web3CheckContext", "contextsSuccess", "context", "contexts", "a", "b", "clearSignContextsOptional", "type", "uncoveredType"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("./BuildBaseContexts"),g=require("./GetWeb3CheckTask");describe("BuildBaseContexts",()=>{const l={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:l,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s.BuildBaseContexts(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),l.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[o,e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[o,e[3],e[1],e[2]],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_INFO,payload:"payload-2"}],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:l,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset},void 0)}),it("should call the context module without challenge for Nano S",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset},void 0)}),it("should call the context module without context on error",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset},void 0)}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,transaction:void 0},i).run(),expect(i).not.toHaveBeenCalled()})});
1
+ "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),l=require("./BuildBaseContexts"),g=require("./GetWeb3CheckTask");describe("BuildBaseContexts",()=>{const s={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:s,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new l.BuildBaseContexts(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),s.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[o,e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[o,e[3],e[1],e[2]],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_INFO,payload:"payload-2"}],o=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:s,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset},l.BASE_CONTEXT_TYPES_FILTER)}),it("should call the context module without challenge for Nano S",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset},l.BASE_CONTEXT_TYPES_FILTER)}),it("should call the context module without context on error",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new l.BuildBaseContexts(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset},l.BASE_CONTEXT_TYPES_FILTER)}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,{...c,transaction:void 0},i).run(),expect(i).not.toHaveBeenCalled()})});
2
2
  //# sourceMappingURL=BuildBaseContexts.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.test.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check,\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check, // web3 check\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n undefined,\n );\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n undefined,\n );\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n undefined,\n );\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAIO,oCACPC,EAOO,2CACPC,EAA4B,kBAG5BC,EAAiC,uCACjCC,EAAgD,6EAEhDC,EAGO,+BACPC,EAAiC,8BAEjC,SAAS,oBAAqB,IAAM,CAClC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,G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I,oBACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkB,mBAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMF,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAI,oBACRA,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BASE_CONTEXT_TYPES_FILTER,\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check,\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check, // web3 check\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n BASE_CONTEXT_TYPES_FILTER,\n );\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n BASE_CONTEXT_TYPES_FILTER,\n );\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n BASE_CONTEXT_TYPES_FILTER,\n );\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAIO,oCACPC,EAOO,2CACPC,EAA4B,kBAG5BC,EAAiC,uCACjCC,EAAgD,6EAEhDC,EAIO,+BACPC,EAAiC,8BAEjC,SAAS,oBAAqB,IAAM,CAClC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,KAAU,mCAAgC,EAC1CC,EAA2B,GAAG,GAAG,EAEvC,SAASC,EACPC,EAC0B,CAC1B,MAAO,CACL,oBAAqB,GACrB,kBAAAA,EACA,gBAAiB,GACjB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,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAI,oBACRA,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
6
6
  "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_ClearSigningType", "import_makeInternalApi", "import_BuildBaseContexts", "import_GetWeb3CheckTask", "contextModuleMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "task", "clearSignContexts", "clearSignContextsOptional", "result", "expectedWeb3Check"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var C=(s,e)=>{for(var o in e)a(s,o,{get:e[o],enumerable:!0})},f=(s,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!p.call(s,t)&&t!==o&&a(s,t,{get:()=>e[t],enumerable:!(n=l(e,t))||n.enumerable});return s};var g=s=>f(a({},"__esModule",{value:!0}),s);var S={};C(S,{BuildSafeAddressContextTask:()=>u});module.exports=g(S);var r=require("@ledgerhq/context-module"),d=require("@ledgerhq/device-management-kit"),i=require("../../app-binder/command/GetChallengeCommand");class u{constructor(e,o){this._api=e;this._args=o}async run(){const e=await this._api.sendCommand(new i.GetChallengeCommand);if(!(0,d.isSuccessCommandResult)(e))throw new Error("Failed to get challenge");const o=e.data.challenge,n=await this._args.contextModule.getContexts({safeContractAddress:this._args.safeContractAddress,chainId:this._args.options.chainId,deviceModelId:this._args.deviceModelId,challenge:o},[r.ClearSignContextType.SAFE,r.ClearSignContextType.SIGNER]);if(n.forEach(t=>{if(t.type===r.ClearSignContextType.ERROR)throw new Error(t.error.message)}),n.length!==2||n.find(t=>t.type===r.ClearSignContextType.SAFE)===void 0||n.find(t=>t.type===r.ClearSignContextType.SIGNER)===void 0)throw new Error("Invalid safe address contexts");return{clearSignContexts:n}}}0&&(module.exports={BuildSafeAddressContextTask});
2
+ //# sourceMappingURL=BuildSafeAddressContextTask.js.map