@ledgerhq/device-signer-kit-ethereum 0.0.0-rnble-transport-20250226091520 → 0.0.0-rnble-transport-20250307123452

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.
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var r=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},S=(n,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of a(e))!r.call(n,t)&&t!==i&&c(n,t,{get:()=>e[t],enumerable:!(o=s(e,t))||o.enumerable});return n};var p=n=>S(c({},"__esModule",{value:!0}),n);var D={};v(D,{makeDeviceActionInternalApiMock:()=>l});module.exports=p(D);const M=vi.fn(),k=vi.fn(),d=vi.fn(),f=vi.fn(),m=vi.fn(),g=vi.fn(),A=vi.fn();function l(){return{sendApdu:M,sendCommand:k,getDeviceSessionState:d,getDeviceSessionStateObservable:f,setDeviceSessionState:m,getManagerApiService:g,getSecureChannelService:A}}0&&(module.exports={makeDeviceActionInternalApiMock});
1
+ "use strict";var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var r=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},S=(n,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of a(e))!r.call(n,t)&&t!==i&&c(n,t,{get:()=>e[t],enumerable:!(o=s(e,t))||o.enumerable});return n};var p=n=>S(c({},"__esModule",{value:!0}),n);var b={};v(b,{makeDeviceActionInternalApiMock:()=>D});module.exports=p(b);const f=vi.fn(),M=vi.fn(),d=vi.fn(),k=vi.fn(),l=vi.fn(),m=vi.fn(),g=vi.fn(),A=vi.fn();function D(){return{sendApdu:f,sendCommand:M,getDeviceSessionState:d,getDeviceSessionStateObservable:k,setDeviceSessionState:l,getManagerApiService:m,getSecureChannelService:g,disableRefresher:A}}0&&(module.exports={makeDeviceActionInternalApiMock});
2
2
  //# sourceMappingURL=makeInternalApi.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts"],
4
- "sourcesContent": ["import { type InternalApi } from \"@ledgerhq/device-management-kit\";\nimport { type Mocked } from \"vitest\";\n\nconst sendApduMock = vi.fn();\nconst sendCommandMock = vi.fn();\nconst apiGetDeviceSessionStateMock = vi.fn();\nconst apiGetDeviceSessionStateObservableMock = vi.fn();\nconst setDeviceSessionStateMock = vi.fn();\nconst getManagerApiServiceMock = vi.fn();\nconst getSecureChannelServiceMock = vi.fn();\n\nexport function makeDeviceActionInternalApiMock(): Mocked<InternalApi> {\n return {\n sendApdu: sendApduMock,\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n getManagerApiService: getManagerApiServiceMock,\n getSecureChannelService: getSecureChannelServiceMock,\n };\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAGA,MAAMI,EAAe,GAAG,GAAG,EACrBC,EAAkB,GAAG,GAAG,EACxBC,EAA+B,GAAG,GAAG,EACrCC,EAAyC,GAAG,GAAG,EAC/CC,EAA4B,GAAG,GAAG,EAClCC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,EAEnC,SAASR,GAAuD,CACrE,MAAO,CACL,SAAUE,EACV,YAAaC,EACb,sBAAuBC,EACvB,gCAAiCC,EACjC,sBAAuBC,EACvB,qBAAsBC,EACtB,wBAAyBC,CAC3B,CACF",
6
- "names": ["makeInternalApi_exports", "__export", "makeDeviceActionInternalApiMock", "__toCommonJS", "sendApduMock", "sendCommandMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "setDeviceSessionStateMock", "getManagerApiServiceMock", "getSecureChannelServiceMock"]
4
+ "sourcesContent": ["import { type InternalApi } from \"@ledgerhq/device-management-kit\";\nimport { type Mocked } from \"vitest\";\n\nconst sendApduMock = vi.fn();\nconst sendCommandMock = vi.fn();\nconst apiGetDeviceSessionStateMock = vi.fn();\nconst apiGetDeviceSessionStateObservableMock = vi.fn();\nconst setDeviceSessionStateMock = vi.fn();\nconst getManagerApiServiceMock = vi.fn();\nconst getSecureChannelServiceMock = vi.fn();\nconst disableRefresherMock = vi.fn();\n\nexport function makeDeviceActionInternalApiMock(): Mocked<InternalApi> {\n return {\n sendApdu: sendApduMock,\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n getManagerApiService: getManagerApiServiceMock,\n getSecureChannelService: getSecureChannelServiceMock,\n disableRefresher: disableRefresherMock,\n };\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAGA,MAAMI,EAAe,GAAG,GAAG,EACrBC,EAAkB,GAAG,GAAG,EACxBC,EAA+B,GAAG,GAAG,EACrCC,EAAyC,GAAG,GAAG,EAC/CC,EAA4B,GAAG,GAAG,EAClCC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,EACpCC,EAAuB,GAAG,GAAG,EAE5B,SAAST,GAAuD,CACrE,MAAO,CACL,SAAUE,EACV,YAAaC,EACb,sBAAuBC,EACvB,gCAAiCC,EACjC,sBAAuBC,EACvB,qBAAsBC,EACtB,wBAAyBC,EACzB,iBAAkBC,CACpB,CACF",
6
+ "names": ["makeInternalApi_exports", "__export", "makeDeviceActionInternalApiMock", "__toCommonJS", "sendApduMock", "sendCommandMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "setDeviceSessionStateMock", "getManagerApiServiceMock", "getSecureChannelServiceMock", "disableRefresherMock"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=require("@ledgerhq/device-management-kit"),e=require("purify-ts"),f=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),t=require("../../typed-data/model/Types"),u=require("./BuildEIP712ContextTask");describe("BuildEIP712ContextTask",()=>{const o=(0,f.makeDeviceActionInternalApiMock)(),i={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},n={parse:vi.fn()},c={domain:{name:"Permit2",chainId:137,verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3"},primaryType:"PermitSingle",message:{details:{token:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",amount:"69420000000000000000",expiration:"1718184249",nonce:"0"},spender:"0xec7be89e9d109e7e3fec59c222cf297125fefda2",sigDeadline:"1715594049"},types:{PermitSingle:[{name:"details",type:"PermitDetails"},{name:"spender",type:"address"},{name:"sigDeadline",type:"uint256"}],PermitDetails:[{name:"token",type:"address"},{name:"amount",type:"uint"},{name:"expiration",type:"uint"},{name:"nonce",type:"uint"}]}},d={PermitSingle:{details:new t.StructType("PermitDetails"),spender:new t.PrimitiveType("address","address",e.Nothing),sigDeadline:new t.PrimitiveType("uint256","uint",(0,e.Just)(32))},PermitDetails:{token:new t.PrimitiveType("address","address",e.Nothing),amount:new t.PrimitiveType("uint160","uint",(0,e.Just)(20)),expiration:new t.PrimitiveType("uint48","uint",(0,e.Just)(6)),nonce:new t.PrimitiveType("uint48","uint",(0,e.Just)(6))}},p=[{path:"",type:"",value:new t.TypedDataValueRoot("EIP712Domain")},{path:"chainId",type:"uint256",value:new t.TypedDataValueField(Uint8Array.from([137]))}],l=[{path:"",type:"",value:new t.TypedDataValueRoot("PermitSingle")},{path:"details.amount",type:"uint160",value:new t.TypedDataValueField(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new t.TypedDataValueField(Uint8Array.from([19]))}],m={type:"success",messageInfo:{displayName:"Permit2",filtersCount:1,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},tokens:{},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"}}};beforeEach(()=>{vi.resetAllMocks()}),it("Build context with clear signing context not supported by the device",async()=>{const s=new u.BuildEIP712ContextTask(o,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:p,message:l})),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Bitcoin",version:"1.0"},deviceModelId:a.DeviceModelId.FLEX});const r=await s.run();expect(r).toStrictEqual({types:d,domain:p,message:l,clearSignContext:e.Nothing,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with no clear signing context",async()=>{const s=new u.BuildEIP712ContextTask(o,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:p,message:l})),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:a.DeviceModelId.FLEX}),i.getTypedDataFilters.mockResolvedValueOnce({type:"error",error:new Error("no filter")});const r=await s.run();expect(r).toStrictEqual({types:d,domain:p,message:l,clearSignContext:e.Nothing,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with clear signing context",async()=>{const s=new u.BuildEIP712ContextTask(o,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:p,message:l})),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:a.DeviceModelId.FLEX}),i.getTypedDataFilters.mockResolvedValueOnce(m);const r=await s.run();expect(r).toStrictEqual({types:d,domain:p,message:l,clearSignContext:(0,e.Just)(m),domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"}),expect(n.parse).toHaveBeenCalledWith(c),expect(i.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v2",schema:c.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context V1",async()=>{const s=new u.BuildEIP712ContextTask(o,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:p,message:l})),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:a.DeviceModelId.FLEX}),i.getTypedDataFilters.mockResolvedValueOnce(m),await s.run(),expect(i.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v1",schema:c.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Should throw error if no primary type",async()=>{const s=new u.BuildEIP712ContextTask(o,i,n,{...c,primaryType:""});n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:p,message:l}));try{await s.run()}catch(r){expect(r).toBeInstanceOf(Error),expect(r.message).toBe('Primary type "" is not defined in the types.')}}),it("Should throw an error if parsing fails",async()=>{const s=new u.BuildEIP712ContextTask(o,i,n,c);n.parse.mockReturnValueOnce((0,e.Left)(new Error("Parsing error")));try{await s.run()}catch(r){expect(r).toBeInstanceOf(Error),expect(r.message).toBe("Parsing error")}})});
1
+ "use strict";var a=require("@ledgerhq/device-management-kit"),e=require("purify-ts"),f=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),t=require("../../typed-data/model/Types"),u=require("./BuildEIP712ContextTask");describe("BuildEIP712ContextTask",()=>{const r=(0,f.makeDeviceActionInternalApiMock)(),i={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},n={parse:vi.fn()},c={domain:{name:"Permit2",chainId:137,verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3"},primaryType:"PermitSingle",message:{details:{token:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",amount:"69420000000000000000",expiration:"1718184249",nonce:"0"},spender:"0xec7be89e9d109e7e3fec59c222cf297125fefda2",sigDeadline:"1715594049"},types:{PermitSingle:[{name:"details",type:"PermitDetails"},{name:"spender",type:"address"},{name:"sigDeadline",type:"uint256"}],PermitDetails:[{name:"token",type:"address"},{name:"amount",type:"uint"},{name:"expiration",type:"uint"},{name:"nonce",type:"uint"}]}},d={PermitSingle:{details:new t.StructType("PermitDetails"),spender:new t.PrimitiveType("address","address",e.Nothing),sigDeadline:new t.PrimitiveType("uint256","uint",(0,e.Just)(32))},PermitDetails:{token:new t.PrimitiveType("address","address",e.Nothing),amount:new t.PrimitiveType("uint160","uint",(0,e.Just)(20)),expiration:new t.PrimitiveType("uint48","uint",(0,e.Just)(6)),nonce:new t.PrimitiveType("uint48","uint",(0,e.Just)(6))}},l=[{path:"",type:"",value:new t.TypedDataValueRoot("EIP712Domain")},{path:"chainId",type:"uint256",value:new t.TypedDataValueField(Uint8Array.from([137]))}],p=[{path:"",type:"",value:new t.TypedDataValueRoot("PermitSingle")},{path:"details.amount",type:"uint160",value:new t.TypedDataValueField(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new t.TypedDataValueField(Uint8Array.from([19]))}],m={type:"success",messageInfo:{displayName:"Permit2",filtersCount:1,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},tokens:{},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"}}};beforeEach(()=>{vi.resetAllMocks()}),it("Build context with clear signing context not supported by the device",async()=>{const s=new u.BuildEIP712ContextTask(r,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:l,message:p})),r.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Bitcoin",version:"1.0"},deviceModelId:a.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await s.run();expect(o).toStrictEqual({types:d,domain:l,message:p,clearSignContext:e.Nothing,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with no clear signing context",async()=>{const s=new u.BuildEIP712ContextTask(r,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:l,message:p})),r.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:a.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),i.getTypedDataFilters.mockResolvedValueOnce({type:"error",error:new Error("no filter")});const o=await s.run();expect(o).toStrictEqual({types:d,domain:l,message:p,clearSignContext:e.Nothing,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with clear signing context",async()=>{const s=new u.BuildEIP712ContextTask(r,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:l,message:p})),r.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:a.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),i.getTypedDataFilters.mockResolvedValueOnce(m);const o=await s.run();expect(o).toStrictEqual({types:d,domain:l,message:p,clearSignContext:(0,e.Just)(m),domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"}),expect(n.parse).toHaveBeenCalledWith(c),expect(i.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v2",schema:c.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context V1",async()=>{const s=new u.BuildEIP712ContextTask(r,i,n,c);n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:l,message:p})),r.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:a.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),i.getTypedDataFilters.mockResolvedValueOnce(m),await s.run(),expect(i.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v1",schema:c.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Should throw error if no primary type",async()=>{const s=new u.BuildEIP712ContextTask(r,i,n,{...c,primaryType:""});n.parse.mockReturnValueOnce((0,e.Right)({types:d,domain:l,message:p}));try{await s.run()}catch(o){expect(o).toBeInstanceOf(Error),expect(o.message).toBe('Primary type "" is not defined in the types.')}}),it("Should throw an error if parsing fails",async()=>{const s=new u.BuildEIP712ContextTask(r,i,n,c);n.parse.mockReturnValueOnce((0,e.Left)(new Error("Parsing error")));try{await s.run()}catch(o){expect(o).toBeInstanceOf(Error),expect(o.message).toBe("Parsing error")}})});
2
2
  //# sourceMappingURL=BuildEIP712ContextTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildEIP712ContextTask.test.ts"],
4
- "sourcesContent": ["import { type TypedDataClearSignContextSuccess } from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { BuildEIP712ContextTask } from \"./BuildEIP712ContextTask\";\n\ndescribe(\"BuildEIP712ContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextMouleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n\n const TEST_DATA = {\n domain: {\n name: \"Permit2\",\n chainId: 137,\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n },\n primaryType: \"PermitSingle\",\n message: {\n details: {\n token: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n amount: \"69420000000000000000\",\n expiration: \"1718184249\",\n nonce: \"0\",\n },\n spender: \"0xec7be89e9d109e7e3fec59c222cf297125fefda2\",\n sigDeadline: \"1715594049\",\n },\n types: {\n PermitSingle: [\n {\n name: \"details\",\n type: \"PermitDetails\",\n },\n {\n name: \"spender\",\n type: \"address\",\n },\n {\n name: \"sigDeadline\",\n type: \"uint256\",\n },\n ],\n PermitDetails: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint\" },\n { name: \"expiration\", type: \"uint\" },\n { name: \"nonce\", type: \"uint\" },\n ],\n },\n };\n\n const TEST_TYPES = {\n PermitSingle: {\n details: new StructType(\"PermitDetails\"),\n spender: new PrimitiveType(\"address\", \"address\", Nothing),\n sigDeadline: new PrimitiveType(\"uint256\", \"uint\", Just(32)),\n },\n PermitDetails: {\n token: new PrimitiveType(\"address\", \"address\", Nothing),\n amount: new PrimitiveType(\"uint160\", \"uint\", Just(20)),\n expiration: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n nonce: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n },\n };\n const TEST_DOMAIN_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"EIP712Domain\"),\n },\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ];\n const TEST_MESSAGE_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"PermitSingle\"),\n },\n {\n path: \"details.amount\",\n type: \"uint160\",\n value: new TypedDataValueField(Uint8Array.from([0x12])),\n },\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ];\n const TEST_CLEAR_SIGN_CONTEXT: TypedDataClearSignContextSuccess = {\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"Build context with clear signing context not supported by the device\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Bitcoin\", version: \"1.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with no clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\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 });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce({\n type: \"error\",\n error: new Error(\"no filter\"),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\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 });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(parserMock.parse).toHaveBeenCalledWith(TEST_DATA);\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v2\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Build context with clear signing context V1\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n await task.run();\n // THEN\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v1\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Should throw error if no primary type\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n {\n ...TEST_DATA,\n primaryType: \"\",\n },\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe('Primary type \"\" is not defined in the types.');\n }\n });\n\n it(\"Should throw an error if parsing fails\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(Left(new Error(\"Parsing error\")));\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe(\"Parsing error\");\n }\n });\n});\n"],
5
- "mappings": "aACA,IAAAA,EAIO,2CACPC,EAA2C,qBAE3CC,EAAgD,6EAChDC,EAKO,4CAEPC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAmB,CACvB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,CAC7B,EACMC,EAAa,CACjB,MAAO,GAAG,GAAG,CACf,EAEMC,EAAY,CAChB,OAAQ,CACN,KAAM,UACN,QAAS,IACT,kBAAmB,4CACrB,EACA,YAAa,eACb,QAAS,CACP,QAAS,CACP,MAAO,6CACP,OAAQ,uBACR,WAAY,aACZ,MAAO,GACT,EACA,QAAS,6CACT,YAAa,YACf,EACA,MAAO,CACL,aAAc,CACZ,CACE,KAAM,UACN,KAAM,eACR,EACA,CACE,KAAM,UACN,KAAM,SACR,EACA,CAC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U,MAClB,aAAc,CACZ,CACE,KAAM,iBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,EACA,CACE,KAAM,qBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,CACF,CACF,CAAC,CACH,CAAC,EAED,GAAG,wCAAyC,SAAY,CAEtD,MAAMK,EAAO,IAAI,yBACfR,EACAC,EACAC,EACA,CACE,GAAGC,EACH,YAAa,EACf,CACF,EACAD,EAAW,MAAM,uBACf,SAAM,CACJ,MAAOE,EACP,OAAQC,EACR,QAASC,CACX,CAAC,CACH,EAEA,GAAI,CACF,MAAME,EAAK,IAAI,CACjB,OAASE,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,8CAA8C,CACvE,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CAEvD,MAAMF,EAAO,IAAI,yBACfR,EACAC,EACAC,EACAC,CACF,EACAD,EAAW,MAAM,uBAAoB,QAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMM,EAAK,IAAI,CACjB,OAASE,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,eAAe,CACxC,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { type TypedDataClearSignContextSuccess } from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { BuildEIP712ContextTask } from \"./BuildEIP712ContextTask\";\n\ndescribe(\"BuildEIP712ContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextMouleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n\n const TEST_DATA = {\n domain: {\n name: \"Permit2\",\n chainId: 137,\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n },\n primaryType: \"PermitSingle\",\n message: {\n details: {\n token: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n amount: \"69420000000000000000\",\n expiration: \"1718184249\",\n nonce: \"0\",\n },\n spender: \"0xec7be89e9d109e7e3fec59c222cf297125fefda2\",\n sigDeadline: \"1715594049\",\n },\n types: {\n PermitSingle: [\n {\n name: \"details\",\n type: \"PermitDetails\",\n },\n {\n name: \"spender\",\n type: \"address\",\n },\n {\n name: \"sigDeadline\",\n type: \"uint256\",\n },\n ],\n PermitDetails: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint\" },\n { name: \"expiration\", type: \"uint\" },\n { name: \"nonce\", type: \"uint\" },\n ],\n },\n };\n\n const TEST_TYPES = {\n PermitSingle: {\n details: new StructType(\"PermitDetails\"),\n spender: new PrimitiveType(\"address\", \"address\", Nothing),\n sigDeadline: new PrimitiveType(\"uint256\", \"uint\", Just(32)),\n },\n PermitDetails: {\n token: new PrimitiveType(\"address\", \"address\", Nothing),\n amount: new PrimitiveType(\"uint160\", \"uint\", Just(20)),\n expiration: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n nonce: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n },\n };\n const TEST_DOMAIN_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"EIP712Domain\"),\n },\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ];\n const TEST_MESSAGE_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"PermitSingle\"),\n },\n {\n path: \"details.amount\",\n type: \"uint160\",\n value: new TypedDataValueField(Uint8Array.from([0x12])),\n },\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ];\n const TEST_CLEAR_SIGN_CONTEXT: TypedDataClearSignContextSuccess = {\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"Build context with clear signing context not supported by the device\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Bitcoin\", version: \"1.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with no clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\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 contextMouleMock.getTypedDataFilters.mockResolvedValueOnce({\n type: \"error\",\n error: new Error(\"no filter\"),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\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 contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(parserMock.parse).toHaveBeenCalledWith(TEST_DATA);\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v2\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Build context with clear signing context V1\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n await task.run();\n // THEN\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v1\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Should throw error if no primary type\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n {\n ...TEST_DATA,\n primaryType: \"\",\n },\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe('Primary type \"\" is not defined in the types.');\n }\n });\n\n it(\"Should throw an error if parsing fails\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(Left(new Error(\"Parsing error\")));\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe(\"Parsing error\");\n }\n });\n});\n"],
5
+ "mappings": "aACA,IAAAA,EAIO,2CACPC,EAA2C,qBAE3CC,EAAgD,6EAChDC,EAKO,4CAEPC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAmB,CACvB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,CAC7B,EACMC,EAAa,CACjB,MAAO,GAAG,GAAG,CACf,EAEMC,EAAY,CAChB,OAAQ,CACN,KAAM,UACN,QAAS,IACT,kBAAmB,4CACrB,EACA,YAAa,eACb,QAAS,CACP,QAAS,CACP,MAAO,6CACP,OAAQ,uBACR,WAAY,aACZ,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gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EACDC,EAAiB,oBAAoB,sBACnCM,CACF,EAEA,MAAMC,EAAK,IAAI,EAEf,OAAOP,EAAiB,mBAAmB,EAAE,qBAAqB,CAChE,kBAAmB,6CACnB,QAAS,IACT,QAAS,KACT,OAAQE,EAAU,MAClB,aAAc,CACZ,CACE,KAAM,iBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,EACA,CACE,KAAM,qBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,CACF,CACF,CAAC,CACH,CAAC,EAED,GAAG,wCAAyC,SAAY,CAEtD,MAAMK,EAAO,IAAI,yBACfR,EACAC,EACAC,EACA,CACE,GAAGC,EACH,YAAa,EACf,CACF,EACAD,EAAW,MAAM,uBACf,SAAM,CACJ,MAAOE,EACP,OAAQC,EACR,QAASC,CACX,CAAC,CACH,EAEA,GAAI,CACF,MAAME,EAAK,IAAI,CACjB,OAASE,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,8CAA8C,CACvE,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CAEvD,MAAMF,EAAO,IAAI,yBACfR,EACAC,EACAC,EACAC,CACF,EACAD,EAAW,MAAM,uBAAoB,QAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMM,EAAK,IAAI,CACjB,OAASE,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,eAAe,CACxC,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_Types", "import_BuildEIP712ContextTask", "apiMock", "contextMouleMock", "parserMock", "TEST_DATA", "TEST_TYPES", "TEST_DOMAIN_VALUES", "TEST_MESSAGE_VALUES", "TEST_CLEAR_SIGN_CONTEXT", "task", "builtContext", "e"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),T=require("ethers"),l=require("purify-ts"),S=require("../../app-binder/constant/plugins"),C=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),u=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const p={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},r={mapTransactionToSubset:vi.fn()},x={domain:"domain-name.eth"},y=(0,e.hexaStringToBuffer)(T.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),c={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,C.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),d={contextModule:p,mapper:r,transaction:y,options:x,challenge:"challenge"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context and a plugin instead of Ethereum app",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:S.ETHEREUM_PLUGINS[0],version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX}),await new u.BuildTransactionContextTask(o,d).run(),expect(r.mapTransactionToSubset).toHaveBeenCalledWith(y)}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX}),await new u.BuildTransactionContextTask(o,d).run(),expect(p.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");r.mapTransactionToSubset.mockReturnValueOnce((0,l.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const t=new u.BuildTransactionContextTask(o,d);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:c},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:c,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should throw an error if the app is not ethereum compatible",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Not Ethereum Compatible",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Unsupported app")}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Transaction info certificate is missing")})});
1
+ "use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),T=require("ethers"),l=require("purify-ts"),S=require("../../app-binder/constant/plugins"),C=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),u=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const p={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},r={mapTransactionToSubset:vi.fn()},x={domain:"domain-name.eth"},y=(0,e.hexaStringToBuffer)(T.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),c={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,C.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),d={contextModule:p,mapper:r,transaction:y,options:x,challenge:"challenge"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context and a plugin instead of Ethereum app",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:S.ETHEREUM_PLUGINS[0],version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new u.BuildTransactionContextTask(o,d).run(),expect(r.mapTransactionToSubset).toHaveBeenCalledWith(y)}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new u.BuildTransactionContextTask(o,d).run(),expect(p.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");r.mapTransactionToSubset.mockReturnValueOnce((0,l.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const t=new u.BuildTransactionContextTask(o,d);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:c},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:c,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should throw an error if the app is not ethereum compatible",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Not Ethereum Compatible",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Unsupported app")}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Transaction info certificate is missing")})});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.test.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ETHEREUM_PLUGINS } from \"@internal/app-binder/constant/plugins\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: 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: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.resetAllMocks();\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n challenge: \"challenge\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context and a plugin instead of Ethereum app\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: ETHEREUM_PLUGINS[0]!, version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n await new BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n await new BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\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 });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should throw an error if the app is not ethereum compatible\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Not Ethereum Compatible\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Unsupported app\");\n });\n\n it(\"should return an error if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\n \"Transaction info certificate is missing\",\n );\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAIO,oCACPC,EAKO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAE5BC,EAAiC,iDACjCC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,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uBAAuB,uBAAoB,SAAMQ,CAAY,CAAC,EACzET,EAAkB,YAAY,sBAAsBQ,CAAiB,EACrEF,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,0BAA2B,QAAS,QAAS,EACjE,cAAe,gBAAc,IAC/B,CAAC,EAGD,MAAMM,EAAO,IAAI,8BAA4BN,EAASD,CAAW,EAGjE,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAAQ,iBAAiB,CAC5D,CAAC,EAED,GAAG,wEAAyE,SAAY,CAEtF,MAAML,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,EACzDC,EAAwC,CAC5C,CACE,KAAM,uBAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACMC,EAAwC,CAC5C,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAN,EAAW,uBAAuB,uBAAoB,SAAMQ,CAAY,CAAC,EACzET,EAAkB,YAAY,sBAAsBQ,CAAiB,EACrEF,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,IAC/B,CAAC,EAGD,MAAMM,EAAO,IAAI,8BAA4BN,EAASD,CAAW,EAGjE,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAC/B,yCACF,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ETHEREUM_PLUGINS } from \"@internal/app-binder/constant/plugins\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: 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: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.resetAllMocks();\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n challenge: \"challenge\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context and a plugin instead of Ethereum app\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: ETHEREUM_PLUGINS[0]!, version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\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 task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should throw an error if the app is not ethereum compatible\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Not Ethereum Compatible\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Unsupported app\");\n });\n\n it(\"should return an error if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\n \"Transaction info certificate is missing\",\n );\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAIO,oCACPC,EAKO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAE5BC,EAAiC,iDACjCC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,CAC7B,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,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,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EAEjBD,EAAc,CACZ,cAAeL,EACf,OAAQC,EACR,YAAaE,EACb,QAASD,EACT,UAAW,WACb,CACF,CAAC,EAED,GAAG,mEAAoE,SAAY,CAEjF,MAAMK,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,C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yE,SAAY,CAEtF,MAAML,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,EACzDC,EAAwC,CAC5C,CACE,KAAM,uBAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACMC,EAAwC,CAC5C,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAN,EAAW,uBAAuB,uBAAoB,SAAMQ,CAAY,CAAC,EACzET,EAAkB,YAAY,sBAAsBQ,CAAiB,EACrEF,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,MAAMM,EAAO,IAAI,8BAA4BN,EAASD,CAAW,EAGjE,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAC/B,yCACF,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_plugins", "import_makeInternalApi", "import_BuildTransactionContextTask", "contextModuleMock", "mapperMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "serializedTransaction", "clearSignContexts", "mapperResult", "result", "error", "task"]
7
7
  }
@@ -53,7 +53,7 @@
53
53
  "@ledgerhq/tsconfig-dsdk": "workspace:*",
54
54
  "@ledgerhq/vitest-config-dmk": "workspace:*",
55
55
  "@types/semver": "^7.5.8",
56
- "rxjs": "^7.8.1",
56
+ "rxjs": "^7.8.2",
57
57
  "ts-node": "^10.9.2"
58
58
  },
59
59
  "peerDependencies": {
@@ -1,2 +1,2 @@
1
- const e=vi.fn(),n=vi.fn(),t=vi.fn(),i=vi.fn(),c=vi.fn(),o=vi.fn(),s=vi.fn();function a(){return{sendApdu:e,sendCommand:n,getDeviceSessionState:t,getDeviceSessionStateObservable:i,setDeviceSessionState:c,getManagerApiService:o,getSecureChannelService:s}}export{a as makeDeviceActionInternalApiMock};
1
+ const e=vi.fn(),n=vi.fn(),t=vi.fn(),i=vi.fn(),c=vi.fn(),o=vi.fn(),s=vi.fn(),a=vi.fn();function r(){return{sendApdu:e,sendCommand:n,getDeviceSessionState:t,getDeviceSessionStateObservable:i,setDeviceSessionState:c,getManagerApiService:o,getSecureChannelService:s,disableRefresher:a}}export{r as makeDeviceActionInternalApiMock};
2
2
  //# sourceMappingURL=makeInternalApi.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts"],
4
- "sourcesContent": ["import { type InternalApi } from \"@ledgerhq/device-management-kit\";\nimport { type Mocked } from \"vitest\";\n\nconst sendApduMock = vi.fn();\nconst sendCommandMock = vi.fn();\nconst apiGetDeviceSessionStateMock = vi.fn();\nconst apiGetDeviceSessionStateObservableMock = vi.fn();\nconst setDeviceSessionStateMock = vi.fn();\nconst getManagerApiServiceMock = vi.fn();\nconst getSecureChannelServiceMock = vi.fn();\n\nexport function makeDeviceActionInternalApiMock(): Mocked<InternalApi> {\n return {\n sendApdu: sendApduMock,\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n getManagerApiService: getManagerApiServiceMock,\n getSecureChannelService: getSecureChannelServiceMock,\n };\n}\n"],
5
- "mappings": "AAGA,MAAMA,EAAe,GAAG,GAAG,EACrBC,EAAkB,GAAG,GAAG,EACxBC,EAA+B,GAAG,GAAG,EACrCC,EAAyC,GAAG,GAAG,EAC/CC,EAA4B,GAAG,GAAG,EAClCC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,EAEnC,SAASC,GAAuD,CACrE,MAAO,CACL,SAAUP,EACV,YAAaC,EACb,sBAAuBC,EACvB,gCAAiCC,EACjC,sBAAuBC,EACvB,qBAAsBC,EACtB,wBAAyBC,CAC3B,CACF",
6
- "names": ["sendApduMock", "sendCommandMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "setDeviceSessionStateMock", "getManagerApiServiceMock", "getSecureChannelServiceMock", "makeDeviceActionInternalApiMock"]
4
+ "sourcesContent": ["import { type InternalApi } from \"@ledgerhq/device-management-kit\";\nimport { type Mocked } from \"vitest\";\n\nconst sendApduMock = vi.fn();\nconst sendCommandMock = vi.fn();\nconst apiGetDeviceSessionStateMock = vi.fn();\nconst apiGetDeviceSessionStateObservableMock = vi.fn();\nconst setDeviceSessionStateMock = vi.fn();\nconst getManagerApiServiceMock = vi.fn();\nconst getSecureChannelServiceMock = vi.fn();\nconst disableRefresherMock = vi.fn();\n\nexport function makeDeviceActionInternalApiMock(): Mocked<InternalApi> {\n return {\n sendApdu: sendApduMock,\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n getManagerApiService: getManagerApiServiceMock,\n getSecureChannelService: getSecureChannelServiceMock,\n disableRefresher: disableRefresherMock,\n };\n}\n"],
5
+ "mappings": "AAGA,MAAMA,EAAe,GAAG,GAAG,EACrBC,EAAkB,GAAG,GAAG,EACxBC,EAA+B,GAAG,GAAG,EACrCC,EAAyC,GAAG,GAAG,EAC/CC,EAA4B,GAAG,GAAG,EAClCC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,EACpCC,EAAuB,GAAG,GAAG,EAE5B,SAASC,GAAuD,CACrE,MAAO,CACL,SAAUR,EACV,YAAaC,EACb,sBAAuBC,EACvB,gCAAiCC,EACjC,sBAAuBC,EACvB,qBAAsBC,EACtB,wBAAyBC,EACzB,iBAAkBC,CACpB,CACF",
6
+ "names": ["sendApduMock", "sendCommandMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "setDeviceSessionStateMock", "getManagerApiServiceMock", "getSecureChannelServiceMock", "disableRefresherMock", "makeDeviceActionInternalApiMock"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as m,DeviceSessionStateType as f,DeviceStatus as y}from"@ledgerhq/device-management-kit";import{Just as l,Left as S,Nothing as b,Right as u}from"purify-ts";import{makeDeviceActionInternalApiMock as v}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{PrimitiveType as d,StructType as T,TypedDataValueField as x,TypedDataValueRoot as h}from"../../typed-data/model/Types";import{BuildEIP712ContextTask as p}from"./BuildEIP712ContextTask";describe("BuildEIP712ContextTask",()=>{const i=v(),t={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},e={parse:vi.fn()},s={domain:{name:"Permit2",chainId:137,verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3"},primaryType:"PermitSingle",message:{details:{token:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",amount:"69420000000000000000",expiration:"1718184249",nonce:"0"},spender:"0xec7be89e9d109e7e3fec59c222cf297125fefda2",sigDeadline:"1715594049"},types:{PermitSingle:[{name:"details",type:"PermitDetails"},{name:"spender",type:"address"},{name:"sigDeadline",type:"uint256"}],PermitDetails:[{name:"token",type:"address"},{name:"amount",type:"uint"},{name:"expiration",type:"uint"},{name:"nonce",type:"uint"}]}},r={PermitSingle:{details:new T("PermitDetails"),spender:new d("address","address",b),sigDeadline:new d("uint256","uint",l(32))},PermitDetails:{token:new d("address","address",b),amount:new d("uint160","uint",l(20)),expiration:new d("uint48","uint",l(6)),nonce:new d("uint48","uint",l(6))}},o=[{path:"",type:"",value:new h("EIP712Domain")},{path:"chainId",type:"uint256",value:new x(Uint8Array.from([137]))}],c=[{path:"",type:"",value:new h("PermitSingle")},{path:"details.amount",type:"uint160",value:new x(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new x(Uint8Array.from([19]))}],g={type:"success",messageInfo:{displayName:"Permit2",filtersCount:1,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},tokens:{},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"}}};beforeEach(()=>{vi.resetAllMocks()}),it("Build context with clear signing context not supported by the device",async()=>{const a=new p(i,t,e,s);e.parse.mockReturnValueOnce(u({types:r,domain:o,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Bitcoin",version:"1.0"},deviceModelId:m.FLEX});const n=await a.run();expect(n).toStrictEqual({types:r,domain:o,message:c,clearSignContext:b,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with no clear signing context",async()=>{const a=new p(i,t,e,s);e.parse.mockReturnValueOnce(u({types:r,domain:o,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:m.FLEX}),t.getTypedDataFilters.mockResolvedValueOnce({type:"error",error:new Error("no filter")});const n=await a.run();expect(n).toStrictEqual({types:r,domain:o,message:c,clearSignContext:b,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with clear signing context",async()=>{const a=new p(i,t,e,s);e.parse.mockReturnValueOnce(u({types:r,domain:o,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:m.FLEX}),t.getTypedDataFilters.mockResolvedValueOnce(g);const n=await a.run();expect(n).toStrictEqual({types:r,domain:o,message:c,clearSignContext:l(g),domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"}),expect(e.parse).toHaveBeenCalledWith(s),expect(t.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v2",schema:s.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context V1",async()=>{const a=new p(i,t,e,s);e.parse.mockReturnValueOnce(u({types:r,domain:o,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:m.FLEX}),t.getTypedDataFilters.mockResolvedValueOnce(g),await a.run(),expect(t.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v1",schema:s.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Should throw error if no primary type",async()=>{const a=new p(i,t,e,{...s,primaryType:""});e.parse.mockReturnValueOnce(u({types:r,domain:o,message:c}));try{await a.run()}catch(n){expect(n).toBeInstanceOf(Error),expect(n.message).toBe('Primary type "" is not defined in the types.')}}),it("Should throw an error if parsing fails",async()=>{const a=new p(i,t,e,s);e.parse.mockReturnValueOnce(S(new Error("Parsing error")));try{await a.run()}catch(n){expect(n).toBeInstanceOf(Error),expect(n.message).toBe("Parsing error")}})});
1
+ import{DeviceModelId as m,DeviceSessionStateType as f,DeviceStatus as y}from"@ledgerhq/device-management-kit";import{Just as p,Left as h,Nothing as b,Right as u}from"purify-ts";import{makeDeviceActionInternalApiMock as v}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{PrimitiveType as d,StructType as C,TypedDataValueField as x,TypedDataValueRoot as S}from"../../typed-data/model/Types";import{BuildEIP712ContextTask as l}from"./BuildEIP712ContextTask";describe("BuildEIP712ContextTask",()=>{const i=v(),t={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},e={parse:vi.fn()},s={domain:{name:"Permit2",chainId:137,verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3"},primaryType:"PermitSingle",message:{details:{token:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",amount:"69420000000000000000",expiration:"1718184249",nonce:"0"},spender:"0xec7be89e9d109e7e3fec59c222cf297125fefda2",sigDeadline:"1715594049"},types:{PermitSingle:[{name:"details",type:"PermitDetails"},{name:"spender",type:"address"},{name:"sigDeadline",type:"uint256"}],PermitDetails:[{name:"token",type:"address"},{name:"amount",type:"uint"},{name:"expiration",type:"uint"},{name:"nonce",type:"uint"}]}},o={PermitSingle:{details:new C("PermitDetails"),spender:new d("address","address",b),sigDeadline:new d("uint256","uint",p(32))},PermitDetails:{token:new d("address","address",b),amount:new d("uint160","uint",p(20)),expiration:new d("uint48","uint",p(6)),nonce:new d("uint48","uint",p(6))}},r=[{path:"",type:"",value:new S("EIP712Domain")},{path:"chainId",type:"uint256",value:new x(Uint8Array.from([137]))}],c=[{path:"",type:"",value:new S("PermitSingle")},{path:"details.amount",type:"uint160",value:new x(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new x(Uint8Array.from([19]))}],g={type:"success",messageInfo:{displayName:"Permit2",filtersCount:1,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},tokens:{},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"}}};beforeEach(()=>{vi.resetAllMocks()}),it("Build context with clear signing context not supported by the device",async()=>{const a=new l(i,t,e,s);e.parse.mockReturnValueOnce(u({types:o,domain:r,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Bitcoin",version:"1.0"},deviceModelId:m.FLEX,isSecureConnectionAllowed:!1});const n=await a.run();expect(n).toStrictEqual({types:o,domain:r,message:c,clearSignContext:b,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with no clear signing context",async()=>{const a=new l(i,t,e,s);e.parse.mockReturnValueOnce(u({types:o,domain:r,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:m.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce({type:"error",error:new Error("no filter")});const n=await a.run();expect(n).toStrictEqual({types:o,domain:r,message:c,clearSignContext:b,domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"})}),it("Build context with clear signing context",async()=>{const a=new l(i,t,e,s);e.parse.mockReturnValueOnce(u({types:o,domain:r,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:m.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce(g);const n=await a.run();expect(n).toStrictEqual({types:o,domain:r,message:c,clearSignContext:p(g),domainHash:"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca",messageHash:"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a"}),expect(e.parse).toHaveBeenCalledWith(s),expect(t.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v2",schema:s.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context V1",async()=>{const a=new l(i,t,e,s);e.parse.mockReturnValueOnce(u({types:o,domain:r,message:c})),i.getDeviceSessionState.mockReturnValueOnce({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:y.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:m.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce(g),await a.run(),expect(t.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v1",schema:s.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Should throw error if no primary type",async()=>{const a=new l(i,t,e,{...s,primaryType:""});e.parse.mockReturnValueOnce(u({types:o,domain:r,message:c}));try{await a.run()}catch(n){expect(n).toBeInstanceOf(Error),expect(n.message).toBe('Primary type "" is not defined in the types.')}}),it("Should throw an error if parsing fails",async()=>{const a=new l(i,t,e,s);e.parse.mockReturnValueOnce(h(new Error("Parsing error")));try{await a.run()}catch(n){expect(n).toBeInstanceOf(Error),expect(n.message).toBe("Parsing error")}})});
2
2
  //# sourceMappingURL=BuildEIP712ContextTask.test.js.map