@ledgerhq/context-module 0.0.0-develop-20260525003143 → 0.0.0-develop-20260526003116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js.map +3 -3
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js.map +3 -3
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map +3 -3
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js +1 -1
- package/lib/cjs/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js.map +3 -3
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.js.map +3 -3
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js.map +3 -3
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map +3 -3
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js +1 -1
- package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js.map +3 -3
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.d.ts +3 -2
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.d.ts.map +1 -1
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts +3 -2
- package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as p}from"@ledgerhq/device-management-kit";import{Left as f,Right as
|
|
1
|
+
import{DeviceModelId as p}from"@ledgerhq/device-management-kit";import{Left as f,Right as c}from"purify-ts";import{GatedSigningContextLoader as y}from"../../../../modules/ethereum/gated-signing/domain/GatedSigningContextLoader";import{KeyId as x}from"../../../../modules/multichain/pki/model/KeyId";import{KeyUsage as m}from"../../../../modules/multichain/pki/model/KeyUsage";import{ClearSignContextType as i}from"../../../../shared/model/ClearSignContext";describe("GatedSigningContextLoader",()=>{const o={getGatedDescriptor:vi.fn(),getGatedDescriptorForTypedData:vi.fn()},n={loadCertificate:vi.fn()},d={getProxyImplementationAddress:vi.fn()},h=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),r=new y(o,n,d,h),g={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},s=[i.ETHEREUM_GATED_SIGNING];beforeEach(()=>{vi.resetAllMocks(),vi.spyOn(n,"loadCertificate").mockResolvedValue(g)}),describe("canHandle function",()=>{const e={to:"0x1111111254fb6c44bac0bed2854e76f90643097d",selector:"0xa1251d75",chainId:1,deviceModelId:p.STAX};it("should return true for valid input",()=>{expect(r.canHandle(e,s)).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(r.canHandle(e,[i.ETHEREUM_TOKEN])).toBe(!1),expect(r.canHandle(e,[i.ETHEREUM_DYNAMIC_NETWORK])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(a,t)=>{expect(r.canHandle(a,s)).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"],[{...e,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(a,t)=>{expect(r.canHandle(a,s)).toBe(!1)}),it.each([[{...e,to:"0x"},"empty to (0x)"],[{...e,to:"not-hex"},"non-hex to"],[{...e,selector:"not-hex"},"non-hex selector"],[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"]])("should return false for %s",(a,t)=>{expect(r.canHandle(a,s)).toBe(!1)})}),describe("load function",()=>{const e={to:"0x1111111254fb6c44bac0bed2854e76f90643097d",selector:"0xa1251d75",chainId:1,deviceModelId:p.STAX},a="010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100";it("should return error context when getGatedDescriptor returns Left and proxy resolution fails",async()=>{const t=new Error("Failed to fetch gated descriptors");vi.spyOn(o,"getGatedDescriptor").mockResolvedValue(f(t)),vi.spyOn(d,"getProxyImplementationAddress").mockResolvedValue(f(new Error("Not a proxy")));const l=await r.load(e);expect(l).toEqual([{type:i.ERROR,error:t}]),expect(o.getGatedDescriptor).toHaveBeenCalledWith({contractAddress:e.to,selector:e.selector,chainId:e.chainId}),expect(d.getProxyImplementationAddress).toHaveBeenCalledWith({proxyAddress:e.to,chainId:e.chainId,challenge:"",calldata:"0x"}),expect(n.loadCertificate).not.toHaveBeenCalled()}),it("should return gated signing context when getGatedDescriptor succeeds",async()=>{vi.spyOn(o,"getGatedDescriptor").mockResolvedValue(c({signedDescriptor:a}));const t=await r.load(e);expect(t).toHaveLength(1),expect(t[0]).toMatchObject({type:i.ETHEREUM_GATED_SIGNING,payload:a,certificate:g}),expect(o.getGatedDescriptor).toHaveBeenCalledWith({contractAddress:e.to,selector:e.selector,chainId:e.chainId}),expect(n.loadCertificate).toHaveBeenCalledWith({keyId:x.CalGatedSigning,keyUsage:m.GatedSigning,targetDevice:e.deviceModelId})}),it("should pass to as contractAddress to getGatedDescriptor",async()=>{const t="0xabcdef1234567890abcdef1234567890abcdef12";vi.spyOn(o,"getGatedDescriptor").mockResolvedValue(c({signedDescriptor:a})),await r.load({...e,to:t}),expect(o.getGatedDescriptor).toHaveBeenCalledWith(expect.objectContaining({contractAddress:t}))}),it("should request certificate for correct device model",async()=>{vi.spyOn(o,"getGatedDescriptor").mockResolvedValue(c({signedDescriptor:a})),await r.load({...e,deviceModelId:p.FLEX}),expect(n.loadCertificate).toHaveBeenCalledWith({keyId:x.CalGatedSigning,keyUsage:m.GatedSigning,targetDevice:p.FLEX})}),it("should reject when certificate loading fails",async()=>{const t=new Error("Certificate loading failed");vi.spyOn(o,"getGatedDescriptor").mockResolvedValue(c({signedDescriptor:a})),vi.spyOn(n,"loadCertificate").mockRejectedValue(t),await expect(r.load(e)).rejects.toThrow(t)}),it("should return PROXY_INFO and GATED_SIGNING when to is proxy and gated descriptor exists for implementation",async()=>{const t="0xabcdef1234567890abcdef1234567890abcdef12",l="0xproxy-descriptor";vi.spyOn(o,"getGatedDescriptor").mockResolvedValueOnce(f(new Error("No gated descriptor"))).mockResolvedValueOnce(c({signedDescriptor:a})),vi.spyOn(d,"getProxyImplementationAddress").mockResolvedValue(c({implementationAddress:t,signedDescriptor:l,keyId:"domain-metadata",keyUsage:"trusted-name"}));const u=await r.load(e);expect(u).toHaveLength(2),expect(u[0]).toMatchObject({type:i.ETHEREUM_PROXY_INFO,payload:l}),expect(u[1]).toMatchObject({type:i.ETHEREUM_GATED_SIGNING,payload:a}),expect(o.getGatedDescriptor).toHaveBeenCalledTimes(2),expect(o.getGatedDescriptor).toHaveBeenNthCalledWith(1,{contractAddress:e.to,selector:e.selector,chainId:e.chainId}),expect(o.getGatedDescriptor).toHaveBeenNthCalledWith(2,{contractAddress:t.toLowerCase(),selector:e.selector,chainId:e.chainId})})})});
|
|
2
2
|
//# sourceMappingURL=GatedSigningContextLoader.test.js.map
|
package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningContextInput,\n GatedSigningContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const loader = new GatedSigningContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"0x\" }, \"empty to (0x)\"],\n [{ ...validInput, to: \"not-hex\" }, \"non-hex to\"],\n [{ ...validInput, selector: \"not-hex\" }, \"non-hex selector\"],\n [{ ...validInput, chainId: \"1\" as unknown as number }, \"string chainId\"],\n [{ ...validInput, chainId: null as unknown as number }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptor returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"Failed to fetch gated descriptors\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.to,\n chainId: validInput.chainId,\n challenge: \"\",\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptor succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should pass to as contractAddress to getGatedDescriptor\", async () => {\n const customTo = \"0xabcdef1234567890abcdef1234567890abcdef12\";\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n to: customTo,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: customTo,\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when to is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptor\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAEE,6BAAAC,MACK,oEAGP,OAAS,SAAAC,MAAa,uCACtB,OAAS,YAAAC,MAAgB,0CAEzB,OAAS,wBAAAC,MAA4B,kCAErC,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAS,
|
|
6
|
-
"names": ["DeviceModelId", "Left", "Right", "GatedSigningContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "signedDescriptor", "error", "result", "customTo", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningContextInput,\n GatedSigningContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const loader = new GatedSigningContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n mockLoggerFactory,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"0x\" }, \"empty to (0x)\"],\n [{ ...validInput, to: \"not-hex\" }, \"non-hex to\"],\n [{ ...validInput, selector: \"not-hex\" }, \"non-hex selector\"],\n [{ ...validInput, chainId: \"1\" as unknown as number }, \"string chainId\"],\n [{ ...validInput, chainId: null as unknown as number }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n const validInput: GatedSigningContextInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptor returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"Failed to fetch gated descriptors\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.to,\n chainId: validInput.chainId,\n challenge: \"\",\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptor succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith({\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should pass to as contractAddress to getGatedDescriptor\", async () => {\n const customTo = \"0xabcdef1234567890abcdef1234567890abcdef12\";\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n to: customTo,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: customTo,\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptor\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when to is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptor\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress: validInput.to,\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptor,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n selector: validInput.selector,\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAEE,6BAAAC,MACK,oEAGP,OAAS,SAAAC,MAAa,uCACtB,OAAS,YAAAC,MAAgB,0CAEzB,OAAS,wBAAAC,MAA4B,kCAErC,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAAS,IAAIR,EACjBI,EACAC,EACAC,EACAC,CACF,EAEME,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAA0C,CAC9CP,EAAqB,sBACvB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAME,EAAuB,iBAAiB,EAAE,kBACjDI,CACF,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,MAAME,EAAuC,CAC3C,GAAI,6CACJ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zD,sBAAsBN,EAAK,IAAI,MAAM,qBAAqB,CAAC,CAAC,EAC5D,sBAAsBC,EAAM,CAAE,iBAAAe,CAAiB,CAAC,CAAC,EACpD,GAAG,MACDR,EACA,+BACF,EAAE,kBACAP,EAAM,CACJ,sBAAAoB,EACA,iBAAkBC,EAClB,MAAO,kBACP,SAAU,cACZ,CAAC,CACH,EAEA,MAAMJ,EAAS,MAAMR,EAAO,KAAKG,CAAU,EAE3C,OAAOK,CAAM,EAAE,aAAa,CAAC,EAC7B,OAAOA,EAAO,CAAC,CAAC,EAAE,cAAc,CAC9B,KAAMb,EAAqB,oBAC3B,QAASiB,CACX,CAAC,EACD,OAAOJ,EAAO,CAAC,CAAC,EAAE,cAAc,CAC9B,KAAMb,EAAqB,uBAC3B,QAASW,CACX,CAAC,EACD,OACEV,EAA8B,kBAChC,EAAE,sBAAsB,CAAC,EACzB,OACEA,EAA8B,kBAChC,EAAE,wBAAwB,EAAG,CAC3B,gBAAiBO,EAAW,GAC5B,SAAUA,EAAW,SACrB,QAASA,EAAW,OACtB,CAAC,EACD,OACEP,EAA8B,kBAChC,EAAE,wBAAwB,EAAG,CAC3B,gBAAiBe,EAAsB,YAAY,EACnD,SAAUR,EAAW,SACrB,QAASA,EAAW,OACtB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "Left", "Right", "GatedSigningContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "mockLoggerFactory", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "signedDescriptor", "error", "result", "customTo", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
7
7
|
}
|
package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var E=(n,e,t,r)=>{for(var a=r>1?void 0:r?k(e,t):e,o=n.length-1,i;o>=0;o--)(i=n[o])&&(a=(r?i(e,t,a):i(a))||a);return r&&a&&I(e,t,a),a},p=(n,e)=>(t,r)=>e(t,r,n);import{inject as l,injectable as v}from"inversify";import{configTypes as w}from"../../../../config/di/configTypes";import{gatedSigningTypes as P}from"../../../../modules/ethereum/gated-signing/di/gatedSigningTypes";import{proxyTypes as H}from"../../../../modules/ethereum/proxy/di/proxyTypes";import{getSchemaHash as A}from"../../../../modules/ethereum/typed-data/utils/getSchemaHash";import{pkiTypes as L}from"../../../../modules/multichain/pki/di/pkiTypes";import{KeyId as C}from"../../../../modules/multichain/pki/model/KeyId";import{KeyUsage as T}from"../../../../modules/multichain/pki/model/KeyUsage";import{ClearSignContextType as s}from"../../../../shared/model/ClearSignContext";const b="0x0000000000000000000000000000000000000000",N=[s.ETHEREUM_GATED_SIGNING];function U(n){if(!n||typeof n!="object")return!1;const e=n;if(!e.types||typeof e.types!="object"||Array.isArray(e.types))return!1;const t=e.types;for(const r of Object.keys(t)){if(typeof r!="string")return!1;const a=t[r];if(!Array.isArray(a))return!1;for(const o of a)if(!o||typeof o!="object"||typeof o.name!="string"||typeof o.type!="string")return!1}return!0}let f=class{constructor(e,t,r,a){this._dataSource=e;this._certificateLoader=t;this._proxyDataSource=r;this.logger=a("GatedSigningTypedDataContextLoader")}logger;canHandle(e,t){return N.every(r=>t.includes(r))&&typeof e=="object"&&e!==null&&"data"in e&&U(e.data)&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&"challenge"in e&&typeof e.challenge=="string"}async load({data:e,chainId:t,deviceModelId:r,challenge:a}){const o=e.domain?.verifyingContract?.toLowerCase()??b,i=o.startsWith("0x")?o:`0x${o}`,d=A(e.types),m=await this._dataSource.getGatedDescriptorForTypedData({contractAddress:i,schemaHash:d,chainId:t});if(m.isRight()){const{signedDescriptor:c}=m.unsafeCoerce(),_=await this._certificateLoader.loadCertificate({keyId:C.CalGatedSigning,keyUsage:T.GatedSigning,targetDevice:r});return this.logger.debug("load result",{data:{path:"direct",verifyingContract:i,schemaHash:d,chainId:t,contextTypes:[s.ETHEREUM_GATED_SIGNING]}}),[{type:s.ETHEREUM_GATED_SIGNING,payload:c,certificate:_}]}const g=m.caseOf({Left:c=>c,Right:()=>new Error("unreachable")}),u=await this._proxyDataSource.getProxyImplementationAddress({proxyAddress:i,chainId:t,challenge:a,calldata:"0x"});if(u.isLeft()){const c=u.extract();return this.logger.warn("Direct gated descriptor lookup failed and proxy resolution failed",{data:{verifyingContract:i,schemaHash:d,chainId:t,directError:g.message,proxyError:c.message}}),[{type:s.ERROR,error:g}]}const y=u.unsafeCoerce(),x=y.implementationAddress.toLowerCase(),S=x.startsWith("0x")?x:`0x${x}`,D=await this._dataSource.getGatedDescriptorForTypedData({contractAddress:S,schemaHash:d,chainId:t});if(D.isLeft()){const c=D.extract();return this.logger.warn("No gated descriptor found for proxy implementation address",{data:{verifyingContract:i,implementationAddress:S,schemaHash:d,chainId:t,directError:g.message,implError:c.message}}),[{type:s.ERROR,error:g}]}const{signedDescriptor:h}=D.unsafeCoerce(),[G,R]=await Promise.all([this._certificateLoader.loadCertificate({keyId:y.keyId,keyUsage:y.keyUsage,targetDevice:r}),this._certificateLoader.loadCertificate({keyId:C.CalGatedSigning,keyUsage:T.GatedSigning,targetDevice:r})]);return this.logger.debug("load result",{data:{path:"proxy",verifyingContract:i,implementationAddress:S,schemaHash:d,chainId:t,contextTypes:[s.ETHEREUM_PROXY_INFO,s.ETHEREUM_GATED_SIGNING]}}),[{type:s.ETHEREUM_PROXY_INFO,payload:y.signedDescriptor,certificate:G},{type:s.ETHEREUM_GATED_SIGNING,payload:h,certificate:R}]}};f=E([v(),p(0,l(P.GatedDescriptorDataSource)),p(1,l(L.PkiCertificateLoader)),p(2,l(H.ProxyDataSource)),p(3,l(w.ContextModuleLoggerFactory))],f);export{f as GatedSigningTypedDataContextLoader};
|
|
2
2
|
//# sourceMappingURL=GatedSigningTypedDataContextLoader.js.map
|
package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DeviceModelId,\n type HexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport { gatedSigningTypes } from \"@/modules/ethereum/gated-signing/di/gatedSigningTypes\";\nimport type { TypedDataSchema } from \"@/modules/ethereum/model/TypedDataContext\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/modules/ethereum/proxy/di/proxyTypes\";\nimport { getSchemaHash } from \"@/modules/ethereum/typed-data/utils/getSchemaHash\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nconst ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport type GatedSigningTypedDataContextInput = {\n data: {\n types: TypedDataSchema;\n domain?: { verifyingContract?: string };\n };\n chainId: number;\n deviceModelId: DeviceModelId;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n];\n\nfunction hasTypedDataShape(\n data: unknown,\n): data is { types: TypedDataSchema; domain?: { verifyingContract?: string } } {\n if (!data || typeof data !== \"object\") return false;\n const obj = data as Record<string, unknown>;\n if (\n !obj[\"types\"] ||\n typeof obj[\"types\"] !== \"object\" ||\n Array.isArray(obj[\"types\"])\n ) {\n return false;\n }\n const types = obj[\"types\"] as Record<string, unknown>;\n for (const key of Object.keys(types)) {\n if (typeof key !== \"string\") return false;\n const value = types[key];\n if (!Array.isArray(value)) return false;\n for (const item of value) {\n if (\n !item ||\n typeof item !== \"object\" ||\n typeof (item as { name?: unknown }).name !== \"string\" ||\n typeof (item as { type?: unknown }).type !== \"string\"\n ) {\n return false;\n }\n }\n }\n return true;\n}\n\n@injectable()\nexport class GatedSigningTypedDataContextLoader\n implements ContextLoader<GatedSigningTypedDataContextInput>\n{\n constructor(\n @inject(gatedSigningTypes.GatedDescriptorDataSource)\n private readonly _dataSource: GatedDescriptorDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(proxyTypes.ProxyDataSource)\n private readonly _proxyDataSource: ProxyDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is GatedSigningTypedDataContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"data\" in input &&\n hasTypedDataShape((input as GatedSigningTypedDataContextInput).data) &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n (input as GatedSigningTypedDataContextInput).deviceModelId !==\n undefined &&\n \"challenge\" in input &&\n typeof (input as GatedSigningTypedDataContextInput).challenge === \"string\"\n );\n }\n\n async load({\n data,\n chainId,\n deviceModelId,\n challenge,\n }: GatedSigningTypedDataContextInput): Promise<ClearSignContext[]> {\n const raw = data.domain?.verifyingContract?.toLowerCase() ?? ZERO_ADDRESS;\n const verifyingContract: HexaString = raw.startsWith(\"0x\")\n ? (raw as HexaString)\n : (`0x${raw}` as HexaString);\n const schemaHash = getSchemaHash(data.types);\n\n const directResult = await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: verifyingContract,\n schemaHash,\n chainId,\n });\n\n if (directResult.isRight()) {\n const { signedDescriptor } = directResult.unsafeCoerce();\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate,\n },\n ];\n }\n\n const firstError: Error = directResult.caseOf({\n Left: (error) => error,\n Right: () => new Error(\"unreachable\"),\n });\n\n const proxyResult =\n await this._proxyDataSource.getProxyImplementationAddress({\n proxyAddress: verifyingContract,\n chainId,\n challenge,\n calldata: \"0x\",\n });\n\n if (proxyResult.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const proxyData = proxyResult.unsafeCoerce();\n const implRaw = proxyData.implementationAddress.toLowerCase();\n const implementationAddress: HexaString = implRaw.startsWith(\"0x\")\n ? (implRaw as HexaString)\n : (`0x${implRaw}` as HexaString);\n\n const implGatedResult =\n await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: implementationAddress,\n schemaHash,\n chainId,\n });\n\n if (implGatedResult.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const { signedDescriptor } = implGatedResult.unsafeCoerce();\n const [proxyCertificate, gatedCertificate] = await Promise.all([\n this._certificateLoader.loadCertificate({\n keyId: proxyData.keyId,\n keyUsage: proxyData.keyUsage,\n targetDevice: deviceModelId,\n }),\n this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n }),\n ]);\n\n return [\n {\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxyData.signedDescriptor,\n certificate: proxyCertificate,\n },\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: gatedCertificate,\n },\n ];\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["inject", "injectable", "gatedSigningTypes", "proxyTypes", "getSchemaHash", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "ZERO_ADDRESS", "SUPPORTED_TYPES", "ClearSignContextType", "hasTypedDataShape", "data", "obj", "types", "key", "value", "item", "GatedSigningTypedDataContextLoader", "_dataSource", "_certificateLoader", "_proxyDataSource", "input", "expectedTypes", "type", "chainId", "deviceModelId", "challenge", "raw", "verifyingContract", "schemaHash", "getSchemaHash", "directResult", "signedDescriptor", "certificate", "KeyId", "KeyUsage", "firstError", "error", "proxyResult", "proxyData", "implRaw", "implementationAddress", "implGatedResult", "proxyCertificate", "gatedCertificate", "__decorateClass", "injectable", "__decorateParam", "inject", "gatedSigningTypes", "pkiTypes", "proxyTypes"]
|
|
4
|
+
"sourcesContent": ["import {\n DeviceModelId,\n type HexaString,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport { gatedSigningTypes } from \"@/modules/ethereum/gated-signing/di/gatedSigningTypes\";\nimport type { TypedDataSchema } from \"@/modules/ethereum/model/TypedDataContext\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/modules/ethereum/proxy/di/proxyTypes\";\nimport { getSchemaHash } from \"@/modules/ethereum/typed-data/utils/getSchemaHash\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nconst ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport type GatedSigningTypedDataContextInput = {\n data: {\n types: TypedDataSchema;\n domain?: { verifyingContract?: string };\n };\n chainId: number;\n deviceModelId: DeviceModelId;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n];\n\nfunction hasTypedDataShape(\n data: unknown,\n): data is { types: TypedDataSchema; domain?: { verifyingContract?: string } } {\n if (!data || typeof data !== \"object\") return false;\n const obj = data as Record<string, unknown>;\n if (\n !obj[\"types\"] ||\n typeof obj[\"types\"] !== \"object\" ||\n Array.isArray(obj[\"types\"])\n ) {\n return false;\n }\n const types = obj[\"types\"] as Record<string, unknown>;\n for (const key of Object.keys(types)) {\n if (typeof key !== \"string\") return false;\n const value = types[key];\n if (!Array.isArray(value)) return false;\n for (const item of value) {\n if (\n !item ||\n typeof item !== \"object\" ||\n typeof (item as { name?: unknown }).name !== \"string\" ||\n typeof (item as { type?: unknown }).type !== \"string\"\n ) {\n return false;\n }\n }\n }\n return true;\n}\n\n@injectable()\nexport class GatedSigningTypedDataContextLoader\n implements ContextLoader<GatedSigningTypedDataContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(gatedSigningTypes.GatedDescriptorDataSource)\n private readonly _dataSource: GatedDescriptorDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(proxyTypes.ProxyDataSource)\n private readonly _proxyDataSource: ProxyDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"GatedSigningTypedDataContextLoader\");\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is GatedSigningTypedDataContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"data\" in input &&\n hasTypedDataShape((input as GatedSigningTypedDataContextInput).data) &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n (input as GatedSigningTypedDataContextInput).deviceModelId !==\n undefined &&\n \"challenge\" in input &&\n typeof (input as GatedSigningTypedDataContextInput).challenge === \"string\"\n );\n }\n\n async load({\n data,\n chainId,\n deviceModelId,\n challenge,\n }: GatedSigningTypedDataContextInput): Promise<ClearSignContext[]> {\n const raw = data.domain?.verifyingContract?.toLowerCase() ?? ZERO_ADDRESS;\n const verifyingContract: HexaString = raw.startsWith(\"0x\")\n ? (raw as HexaString)\n : (`0x${raw}` as HexaString);\n const schemaHash = getSchemaHash(data.types);\n\n const directResult = await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: verifyingContract,\n schemaHash,\n chainId,\n });\n\n if (directResult.isRight()) {\n const { signedDescriptor } = directResult.unsafeCoerce();\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n });\n this.logger.debug(\"load result\", {\n data: {\n path: \"direct\",\n verifyingContract,\n schemaHash,\n chainId,\n contextTypes: [ClearSignContextType.ETHEREUM_GATED_SIGNING],\n },\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate,\n },\n ];\n }\n\n const firstError: Error = directResult.caseOf({\n Left: (error) => error,\n Right: () => new Error(\"unreachable\"),\n });\n\n const proxyResult =\n await this._proxyDataSource.getProxyImplementationAddress({\n proxyAddress: verifyingContract,\n chainId,\n challenge,\n calldata: \"0x\",\n });\n\n if (proxyResult.isLeft()) {\n const proxyError = proxyResult.extract() as Error;\n this.logger.warn(\n \"Direct gated descriptor lookup failed and proxy resolution failed\",\n {\n data: {\n verifyingContract,\n schemaHash,\n chainId,\n directError: firstError.message,\n proxyError: proxyError.message,\n },\n },\n );\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const proxyData = proxyResult.unsafeCoerce();\n const implRaw = proxyData.implementationAddress.toLowerCase();\n const implementationAddress: HexaString = implRaw.startsWith(\"0x\")\n ? (implRaw as HexaString)\n : (`0x${implRaw}` as HexaString);\n\n const implGatedResult =\n await this._dataSource.getGatedDescriptorForTypedData({\n contractAddress: implementationAddress,\n schemaHash,\n chainId,\n });\n\n if (implGatedResult.isLeft()) {\n const implError = implGatedResult.extract() as Error;\n this.logger.warn(\n \"No gated descriptor found for proxy implementation address\",\n {\n data: {\n verifyingContract,\n implementationAddress,\n schemaHash,\n chainId,\n directError: firstError.message,\n implError: implError.message,\n },\n },\n );\n return [\n {\n type: ClearSignContextType.ERROR,\n error: firstError,\n },\n ];\n }\n\n const { signedDescriptor } = implGatedResult.unsafeCoerce();\n const [proxyCertificate, gatedCertificate] = await Promise.all([\n this._certificateLoader.loadCertificate({\n keyId: proxyData.keyId,\n keyUsage: proxyData.keyUsage,\n targetDevice: deviceModelId,\n }),\n this._certificateLoader.loadCertificate({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: deviceModelId,\n }),\n ]);\n\n this.logger.debug(\"load result\", {\n data: {\n path: \"proxy\",\n verifyingContract,\n implementationAddress,\n schemaHash,\n chainId,\n contextTypes: [\n ClearSignContextType.ETHEREUM_PROXY_INFO,\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ],\n },\n });\n return [\n {\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxyData.signedDescriptor,\n certificate: proxyCertificate,\n },\n {\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: gatedCertificate,\n },\n ];\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAKA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAE5B,OAAS,qBAAAC,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6
|
+
"names": ["inject", "injectable", "configTypes", "gatedSigningTypes", "proxyTypes", "getSchemaHash", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "ZERO_ADDRESS", "SUPPORTED_TYPES", "ClearSignContextType", "hasTypedDataShape", "data", "obj", "types", "key", "value", "item", "GatedSigningTypedDataContextLoader", "_dataSource", "_certificateLoader", "_proxyDataSource", "loggerFactory", "input", "expectedTypes", "type", "chainId", "deviceModelId", "challenge", "raw", "verifyingContract", "schemaHash", "getSchemaHash", "directResult", "signedDescriptor", "certificate", "KeyId", "KeyUsage", "firstError", "error", "proxyResult", "proxyError", "proxyData", "implRaw", "implementationAddress", "implGatedResult", "implError", "proxyCertificate", "gatedCertificate", "__decorateClass", "injectable", "__decorateParam", "inject", "gatedSigningTypes", "pkiTypes", "proxyTypes", "configTypes"]
|
|
7
7
|
}
|
package/lib/esm/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as
|
|
1
|
+
import{DeviceModelId as r}from"@ledgerhq/device-management-kit";import{Left as g,Right as s}from"purify-ts";import{GatedSigningTypedDataContextLoader as x}from"../../../../modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader";import{KeyId as f}from"../../../../modules/multichain/pki/model/KeyId";import{KeyUsage as m}from"../../../../modules/multichain/pki/model/KeyUsage";import{ClearSignContextType as i}from"../../../../shared/model/ClearSignContext";describe("GatedSigningTypedDataContextLoader",()=>{const a={getGatedDescriptor:vi.fn(),getGatedDescriptorForTypedData:vi.fn()},c={loadCertificate:vi.fn()},l={getProxyImplementationAddress:vi.fn()},u=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),t=new x(a,c,l,u),h={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},n=[i.ETHEREUM_GATED_SIGNING],e={data:{types:{EIP712Domain:[{name:"name",type:"string"},{name:"chainId",type:"uint256"}],Mail:[{name:"subject",type:"string"}]},domain:{verifyingContract:"0x1111111254fb6c44bac0bed2854e76f90643097d"}},chainId:1,deviceModelId:r.STAX,challenge:"test-challenge"};beforeEach(()=>{vi.resetAllMocks(),vi.spyOn(c,"loadCertificate").mockResolvedValue(h)}),describe("canHandle",()=>{it("should return true for valid typed data input",()=>{expect(t.canHandle(e,n)).toBe(!0)}),it("should return false when expected types do not include GATED_SIGNING",()=>{expect(t.canHandle(e,[i.ETHEREUM_TOKEN])).toBe(!1),expect(t.canHandle(e,[i.ETHEREUM_DYNAMIC_NETWORK])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"]])("should return false for %s",(d,o)=>{expect(t.canHandle(d,n)).toBe(!1)}),it("should return false for transaction-style input (selector, to)",()=>{const d={to:"0x1111111254fb6c44bac0bed2854e76f90643097d",selector:"0xa1251d75",chainId:1,deviceModelId:r.STAX};expect(t.canHandle(d,n)).toBe(!1)}),it("should return false when data is missing",()=>{expect(t.canHandle({chainId:1,deviceModelId:r.STAX},n)).toBe(!1)}),it("should return false when data.types is not a valid schema",()=>{expect(t.canHandle({data:{types:"not-an-object"},chainId:1,deviceModelId:r.STAX,challenge:e.challenge},n)).toBe(!1),expect(t.canHandle({data:{types:{}},chainId:1,deviceModelId:r.STAX,challenge:e.challenge},n)).toBe(!0)}),it("should return false when chainId or deviceModelId is missing",()=>{expect(t.canHandle({data:e.data,deviceModelId:r.STAX,challenge:e.challenge},n)).toBe(!1),expect(t.canHandle({data:e.data,chainId:1,challenge:e.challenge},n)).toBe(!1)}),it("should return false when challenge is missing",()=>{expect(t.canHandle({data:e.data,chainId:1,deviceModelId:r.STAX},n)).toBe(!1)})}),describe("load",()=>{const d="010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100";it("should return error context when getGatedDescriptorForTypedData returns Left and proxy resolution fails",async()=>{const o=new Error("No gated descriptor for schema hash");vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue(g(o)),vi.spyOn(l,"getProxyImplementationAddress").mockResolvedValue(g(new Error("Not a proxy")));const p=await t.load(e);expect(p).toEqual([{type:i.ERROR,error:o}]),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledWith({contractAddress:e.data.domain.verifyingContract.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId}),expect(l.getProxyImplementationAddress).toHaveBeenCalledWith({proxyAddress:e.data.domain.verifyingContract.toLowerCase(),chainId:e.chainId,challenge:e.challenge,calldata:"0x"}),expect(c.loadCertificate).not.toHaveBeenCalled()}),it("should return gated signing context when getGatedDescriptorForTypedData succeeds",async()=>{vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue(s({signedDescriptor:d}));const o=await t.load(e);expect(o).toHaveLength(1),expect(o[0]).toMatchObject({type:i.ETHEREUM_GATED_SIGNING,payload:d,certificate:h}),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledWith({contractAddress:e.data.domain.verifyingContract.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId}),expect(c.loadCertificate).toHaveBeenCalledWith({keyId:f.CalGatedSigning,keyUsage:m.GatedSigning,targetDevice:e.deviceModelId})}),it("should use zero address when domain.verifyingContract is missing",async()=>{vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue(s({signedDescriptor:d})),await t.load({data:{types:e.data.types},chainId:e.chainId,deviceModelId:e.deviceModelId,challenge:e.challenge}),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledWith(expect.objectContaining({contractAddress:"0x0000000000000000000000000000000000000000"}))}),it("should request certificate for correct device model",async()=>{vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue(s({signedDescriptor:d})),await t.load({...e,deviceModelId:r.FLEX}),expect(c.loadCertificate).toHaveBeenCalledWith({keyId:f.CalGatedSigning,keyUsage:m.GatedSigning,targetDevice:r.FLEX})}),it("should reject when certificate loading fails",async()=>{const o=new Error("Certificate loading failed");vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValue(s({signedDescriptor:d})),vi.spyOn(c,"loadCertificate").mockRejectedValue(o),await expect(t.load(e)).rejects.toThrow(o)}),it("should return PROXY_INFO and GATED_SIGNING when verifying contract is proxy and gated descriptor exists for implementation",async()=>{const o="0xabcdef1234567890abcdef1234567890abcdef12",p="0xproxy-descriptor";vi.spyOn(a,"getGatedDescriptorForTypedData").mockResolvedValueOnce(g(new Error("No gated descriptor"))).mockResolvedValueOnce(s({signedDescriptor:d})),vi.spyOn(l,"getProxyImplementationAddress").mockResolvedValue(s({implementationAddress:o,signedDescriptor:p,keyId:"domain-metadata",keyUsage:"trusted-name"}));const y=await t.load(e);expect(y).toHaveLength(2),expect(y[0]).toMatchObject({type:i.ETHEREUM_PROXY_INFO,payload:p}),expect(y[1]).toMatchObject({type:i.ETHEREUM_GATED_SIGNING,payload:d}),expect(a.getGatedDescriptorForTypedData).toHaveBeenCalledTimes(2),expect(a.getGatedDescriptorForTypedData).toHaveBeenNthCalledWith(1,{contractAddress:e.data.domain.verifyingContract.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId}),expect(a.getGatedDescriptorForTypedData).toHaveBeenNthCalledWith(2,{contractAddress:o.toLowerCase(),schemaHash:expect.any(String),chainId:e.chainId})})})});
|
|
2
2
|
//# sourceMappingURL=GatedSigningTypedDataContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningTypedDataContextInput,\n GatedSigningTypedDataContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningTypedDataContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const loader = new GatedSigningTypedDataContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n const validInput: GatedSigningTypedDataContextInput = {\n data: {\n types: {\n EIP712Domain: [\n { name: \"name\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n Mail: [{ name: \"subject\", type: \"string\" }],\n },\n domain: {\n verifyingContract: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n },\n },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: \"test-challenge\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid typed data input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false when expected types do not include GATED_SIGNING\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false for transaction-style input (selector, to)\", () => {\n const transactionInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n expect(loader.canHandle(transactionInput, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false when data is missing\", () => {\n expect(\n loader.canHandle(\n { chainId: 1, deviceModelId: DeviceModelId.STAX },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when data.types is not a valid schema\", () => {\n expect(\n loader.canHandle(\n {\n data: { types: \"not-an-object\" },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: { types: {} },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(true);\n });\n\n it(\"should return false when chainId or deviceModelId is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when challenge is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptorForTypedData returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"No gated descriptor for schema hash\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.data.domain!.verifyingContract!.toLowerCase(),\n chainId: validInput.chainId,\n challenge: validInput.challenge,\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptorForTypedData succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should use zero address when domain.verifyingContract is missing\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n data: { types: validInput.data.types },\n chainId: validInput.chainId,\n deviceModelId: validInput.deviceModelId,\n challenge: validInput.challenge,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: \"0x0000000000000000000000000000000000000000\",\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when verifying contract is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptorForTypedData\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAEE,sCAAAC,MACK,6EAGP,OAAS,SAAAC,MAAa,uCACtB,OAAS,YAAAC,MAAgB,0CAEzB,OAAS,wBAAAC,MAA4B,kCAErC,SAAS,qCAAsC,IAAM,CACnD,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAS,
|
|
6
|
-
"names": ["DeviceModelId", "Left", "Right", "GatedSigningTypedDataContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "transactionInput", "signedDescriptor", "error", "result", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type GatedDescriptorDataSource } from \"@/modules/ethereum/gated-signing/data/GatedDescriptorDataSource\";\nimport {\n type GatedSigningTypedDataContextInput,\n GatedSigningTypedDataContextLoader,\n} from \"@/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader\";\nimport type { ProxyDataSource } from \"@/modules/ethereum/proxy/data/ProxyDataSource\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"GatedSigningTypedDataContextLoader\", () => {\n const mockGatedDescriptorDataSource: GatedDescriptorDataSource = {\n getGatedDescriptor: vi.fn(),\n getGatedDescriptorForTypedData: vi.fn(),\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const loader = new GatedSigningTypedDataContextLoader(\n mockGatedDescriptorDataSource,\n mockCertificateLoader,\n mockProxyDataSource,\n mockLoggerFactory,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ETHEREUM_GATED_SIGNING,\n ];\n\n const validInput: GatedSigningTypedDataContextInput = {\n data: {\n types: {\n EIP712Domain: [\n { name: \"name\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n Mail: [{ name: \"subject\", type: \"string\" }],\n },\n domain: {\n verifyingContract: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n },\n },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: \"test-challenge\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid typed data input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false when expected types do not include GATED_SIGNING\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ETHEREUM_TOKEN]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ETHEREUM_DYNAMIC_NETWORK,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false for transaction-style input (selector, to)\", () => {\n const transactionInput = {\n to: \"0x1111111254fb6c44bac0bed2854e76f90643097d\",\n selector: \"0xa1251d75\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n expect(loader.canHandle(transactionInput, SUPPORTED_TYPES)).toBe(false);\n });\n\n it(\"should return false when data is missing\", () => {\n expect(\n loader.canHandle(\n { chainId: 1, deviceModelId: DeviceModelId.STAX },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when data.types is not a valid schema\", () => {\n expect(\n loader.canHandle(\n {\n data: { types: \"not-an-object\" },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: { types: {} },\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(true);\n });\n\n it(\"should return false when chainId or deviceModelId is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n deviceModelId: DeviceModelId.STAX,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n challenge: validInput.challenge,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n\n it(\"should return false when challenge is missing\", () => {\n expect(\n loader.canHandle(\n {\n data: validInput.data,\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n },\n SUPPORTED_TYPES,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n const signedDescriptor =\n \"010122020101222a30783131313131313235346662366334346261633062656432383534653736663930363433303937642308000000000000000140086131323531643735150100\";\n\n it(\"should return error context when getGatedDescriptorForTypedData returns Left and proxy resolution fails\", async () => {\n const error = new Error(\"No gated descriptor for schema hash\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Left(error));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(new Error(\"Not a proxy\")));\n\n const result = await loader.load(validInput);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n proxyAddress: validInput.data.domain!.verifyingContract!.toLowerCase(),\n chainId: validInput.chainId,\n challenge: validInput.challenge,\n calldata: \"0x\",\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return gated signing context when getGatedDescriptorForTypedData succeeds\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n certificate: mockCertificate,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith({\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: validInput.deviceModelId,\n });\n });\n\n it(\"should use zero address when domain.verifyingContract is missing\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n data: { types: validInput.data.types },\n chainId: validInput.chainId,\n deviceModelId: validInput.deviceModelId,\n challenge: validInput.challenge,\n });\n\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledWith(\n expect.objectContaining({\n contractAddress: \"0x0000000000000000000000000000000000000000\",\n }),\n );\n });\n\n it(\"should request certificate for correct device model\", async () => {\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n\n await loader.load({\n ...validInput,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalGatedSigning,\n keyUsage: KeyUsage.GatedSigning,\n targetDevice: DeviceModelId.FLEX,\n });\n });\n\n it(\"should reject when certificate loading fails\", async () => {\n const certificateError = new Error(\"Certificate loading failed\");\n vi.spyOn(\n mockGatedDescriptorDataSource,\n \"getGatedDescriptorForTypedData\",\n ).mockResolvedValue(Right({ signedDescriptor }));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n certificateError,\n );\n\n await expect(loader.load(validInput)).rejects.toThrow(certificateError);\n });\n\n it(\"should return PROXY_INFO and GATED_SIGNING when verifying contract is proxy and gated descriptor exists for implementation\", async () => {\n const implementationAddress =\n \"0xabcdef1234567890abcdef1234567890abcdef12\";\n const proxySignedDescriptor = \"0xproxy-descriptor\";\n vi.spyOn(mockGatedDescriptorDataSource, \"getGatedDescriptorForTypedData\")\n .mockResolvedValueOnce(Left(new Error(\"No gated descriptor\")))\n .mockResolvedValueOnce(Right({ signedDescriptor }));\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(\n Right({\n implementationAddress,\n signedDescriptor: proxySignedDescriptor,\n keyId: \"domain-metadata\",\n keyUsage: \"trusted-name\",\n }),\n );\n\n const result = await loader.load(validInput);\n\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_PROXY_INFO,\n payload: proxySignedDescriptor,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.ETHEREUM_GATED_SIGNING,\n payload: signedDescriptor,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenCalledTimes(2);\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(1, {\n contractAddress:\n validInput.data.domain!.verifyingContract!.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n expect(\n mockGatedDescriptorDataSource.getGatedDescriptorForTypedData,\n ).toHaveBeenNthCalledWith(2, {\n contractAddress: implementationAddress.toLowerCase(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n schemaHash: expect.any(String),\n chainId: validInput.chainId,\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAEE,sCAAAC,MACK,6EAGP,OAAS,SAAAC,MAAa,uCACtB,OAAS,YAAAC,MAAgB,0CAEzB,OAAS,wBAAAC,MAA4B,kCAErC,SAAS,qCAAsC,IAAM,CACnD,MAAMC,EAA2D,CAC/D,mBAAoB,GAAG,GAAG,EAC1B,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EAEMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAAS,IAAIR,EACjBI,EACAC,EACAC,EACAC,CACF,EAEME,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAA0C,CAC9CP,EAAq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CAAC,EACzB,OACEA,EAA8B,8BAChC,EAAE,wBAAwB,EAAG,CAC3B,gBACEO,EAAW,KAAK,OAAQ,kBAAmB,YAAY,EAEzD,WAAY,OAAO,IAAI,MAAM,EAC7B,QAASA,EAAW,OACtB,CAAC,EACD,OACEP,EAA8B,8BAChC,EAAE,wBAAwB,EAAG,CAC3B,gBAAiBe,EAAsB,YAAY,EAEnD,WAAY,OAAO,IAAI,MAAM,EAC7B,QAASR,EAAW,OACtB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "Left", "Right", "GatedSigningTypedDataContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "mockGatedDescriptorDataSource", "mockCertificateLoader", "mockProxyDataSource", "mockLoggerFactory", "loader", "mockCertificate", "SUPPORTED_TYPES", "validInput", "input", "_description", "transactionInput", "signedDescriptor", "error", "result", "certificateError", "implementationAddress", "proxySignedDescriptor"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeviceModelId, HexaString } from "@ledgerhq/device-management-kit";
|
|
1
|
+
import { DeviceModelId, HexaString, LoggerPublisherService } from "@ledgerhq/device-management-kit";
|
|
2
2
|
import { type GatedDescriptorDataSource } from "../../../../modules/ethereum/gated-signing/data/GatedDescriptorDataSource";
|
|
3
3
|
import type { ProxyDataSource } from "../../../../modules/ethereum/proxy/data/ProxyDataSource";
|
|
4
4
|
import { type PkiCertificateLoader } from "../../../../modules/multichain/pki/domain/PkiCertificateLoader";
|
|
@@ -14,7 +14,8 @@ export declare class GatedSigningContextLoader implements ContextLoader<GatedSig
|
|
|
14
14
|
private readonly _dataSource;
|
|
15
15
|
private readonly _certificateLoader;
|
|
16
16
|
private readonly _proxyDataSource;
|
|
17
|
-
|
|
17
|
+
private readonly logger;
|
|
18
|
+
constructor(_dataSource: GatedDescriptorDataSource, _certificateLoader: PkiCertificateLoader, _proxyDataSource: ProxyDataSource, loggerFactory: (tag: string) => LoggerPublisherService);
|
|
18
19
|
canHandle(input: unknown, expectedTypes: ClearSignContextType[]): input is GatedSigningContextInput;
|
|
19
20
|
load({ to, selector, chainId, deviceModelId, }: GatedSigningContextInput): Promise<ClearSignContext[]>;
|
|
20
21
|
private _loadGatedCertificate;
|
package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatedSigningContextLoader.d.ts","sourceRoot":"","sources":["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,
|
|
1
|
+
{"version":3,"file":"GatedSigningContextLoader.d.ts","sourceRoot":"","sources":["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningContextLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EAEV,sBAAsB,EACvB,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,iEAAiE,CAAC;AAEjH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAGrF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAGjG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,EAAE,UAAU,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAWF,qBACa,yBACX,YAAW,aAAa,CAAC,wBAAwB,CAAC;IAMhD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAE5B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IAEnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IARnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;gBAI7B,WAAW,EAAE,yBAAyB,EAEtC,kBAAkB,EAAE,oBAAoB,EAExC,gBAAgB,EAAE,eAAe,EAElD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAKxD,SAAS,CACP,KAAK,EAAE,OAAO,EACd,aAAa,EAAE,oBAAoB,EAAE,GACpC,KAAK,IAAI,wBAAwB;IAiB9B,IAAI,CAAC,EACT,EAAE,EACF,QAAQ,EACR,OAAO,EACP,aAAa,GACd,EAAE,wBAAwB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IA6HzD,OAAO,CAAC,qBAAqB;CAO9B"}
|
package/lib/types/src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeviceModelId } from "@ledgerhq/device-management-kit";
|
|
1
|
+
import { DeviceModelId, LoggerPublisherService } from "@ledgerhq/device-management-kit";
|
|
2
2
|
import { type GatedDescriptorDataSource } from "../../../../modules/ethereum/gated-signing/data/GatedDescriptorDataSource";
|
|
3
3
|
import type { TypedDataSchema } from "../../../../modules/ethereum/model/TypedDataContext";
|
|
4
4
|
import type { ProxyDataSource } from "../../../../modules/ethereum/proxy/data/ProxyDataSource";
|
|
@@ -20,7 +20,8 @@ export declare class GatedSigningTypedDataContextLoader implements ContextLoader
|
|
|
20
20
|
private readonly _dataSource;
|
|
21
21
|
private readonly _certificateLoader;
|
|
22
22
|
private readonly _proxyDataSource;
|
|
23
|
-
|
|
23
|
+
private readonly logger;
|
|
24
|
+
constructor(_dataSource: GatedDescriptorDataSource, _certificateLoader: PkiCertificateLoader, _proxyDataSource: ProxyDataSource, loggerFactory: (tag: string) => LoggerPublisherService);
|
|
24
25
|
canHandle(input: unknown, expectedTypes: ClearSignContextType[]): input is GatedSigningTypedDataContextInput;
|
|
25
26
|
load({ data, chainId, deviceModelId, challenge, }: GatedSigningTypedDataContextInput): Promise<ClearSignContext[]>;
|
|
26
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatedSigningTypedDataContextLoader.d.ts","sourceRoot":"","sources":["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"GatedSigningTypedDataContextLoader.d.ts","sourceRoot":"","sources":["../../../../../../../src/modules/ethereum/gated-signing/domain/GatedSigningTypedDataContextLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,sBAAsB,EACvB,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,iEAAiE,CAAC;AAEjH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAIrF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAGjG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,iCAAiC,CAAC;AAIzC,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE;QACJ,KAAK,EAAE,eAAe,CAAC;QACvB,MAAM,CAAC,EAAE;YAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KACzC,CAAC;IACF,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAqCF,qBACa,kCACX,YAAW,aAAa,CAAC,iCAAiC,CAAC;IAMzD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAE5B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IAEnC,OAAO,CAAC,QAAQ,CAA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