@ledgerhq/speculos-device-controller 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/lib/cjs/package.json +4 -5
- package/lib/cjs/src/api/DeviceController.js +1 -1
- package/lib/cjs/src/api/DeviceController.js.map +2 -2
- package/lib/cjs/src/api/DeviceController.test.js +1 -1
- package/lib/cjs/src/api/DeviceController.test.js.map +3 -3
- package/lib/cjs/src/internal/adapters/DefaultButtonController.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultButtonController.js.map +2 -2
- package/lib/cjs/src/internal/adapters/DefaultButtonController.test.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultButtonController.test.js.map +3 -3
- package/lib/cjs/src/internal/adapters/DefaultTouchController.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultTouchController.js.map +2 -2
- package/lib/cjs/src/internal/adapters/DefaultTouchController.test.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultTouchController.test.js.map +3 -3
- package/lib/cjs/src/internal/core/types.js +1 -1
- package/lib/cjs/src/internal/core/types.js.map +2 -2
- package/lib/cjs/src/internal/di.js +1 -1
- package/lib/cjs/src/internal/di.js.map +3 -3
- package/lib/cjs/src/internal/di.test.js +1 -1
- package/lib/cjs/src/internal/di.test.js.map +3 -3
- package/lib/cjs/src/internal/use-cases/touchUseCases.js +1 -1
- package/lib/cjs/src/internal/use-cases/touchUseCases.js.map +3 -3
- package/lib/cjs/src/internal/use-cases/touchUseCases.test.js +1 -1
- package/lib/cjs/src/internal/use-cases/touchUseCases.test.js.map +3 -3
- package/lib/esm/package.json +4 -5
- package/lib/esm/src/api/DeviceController.js +1 -1
- package/lib/esm/src/api/DeviceController.js.map +3 -3
- package/lib/esm/src/api/DeviceController.test.js +1 -1
- package/lib/esm/src/api/DeviceController.test.js.map +3 -3
- package/lib/esm/src/internal/adapters/DefaultButtonController.js.map +2 -2
- package/lib/esm/src/internal/adapters/DefaultButtonController.test.js +1 -1
- package/lib/esm/src/internal/adapters/DefaultButtonController.test.js.map +3 -3
- package/lib/esm/src/internal/adapters/DefaultTouchController.js +1 -1
- package/lib/esm/src/internal/adapters/DefaultTouchController.js.map +2 -2
- package/lib/esm/src/internal/adapters/DefaultTouchController.test.js +1 -1
- package/lib/esm/src/internal/adapters/DefaultTouchController.test.js.map +3 -3
- package/lib/esm/src/internal/core/types.js.map +2 -2
- package/lib/esm/src/internal/di.js +1 -1
- package/lib/esm/src/internal/di.js.map +3 -3
- package/lib/esm/src/internal/di.test.js +1 -1
- package/lib/esm/src/internal/di.test.js.map +3 -3
- package/lib/esm/src/internal/use-cases/touchUseCases.js +1 -1
- package/lib/esm/src/internal/use-cases/touchUseCases.js.map +3 -3
- package/lib/esm/src/internal/use-cases/touchUseCases.test.js +1 -1
- package/lib/esm/src/internal/use-cases/touchUseCases.test.js.map +3 -3
- package/lib/types/src/api/DeviceController.d.ts +7 -0
- package/lib/types/src/api/DeviceController.d.ts.map +1 -1
- package/lib/types/src/internal/adapters/DefaultButtonController.d.ts +2 -3
- package/lib/types/src/internal/adapters/DefaultButtonController.d.ts.map +1 -1
- package/lib/types/src/internal/adapters/DefaultTouchController.d.ts +2 -3
- package/lib/types/src/internal/adapters/DefaultTouchController.d.ts.map +1 -1
- package/lib/types/src/internal/core/types.d.ts +4 -0
- package/lib/types/src/internal/core/types.d.ts.map +1 -1
- package/lib/types/src/internal/di.d.ts.map +1 -1
- package/lib/types/src/internal/use-cases/touchUseCases.d.ts +6 -0
- package/lib/types/src/internal/use-cases/touchUseCases.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +4 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/use-cases/touchUseCases.test.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport type { TouchController } from \"@root/src/internal/core/TouchController\";\n\nimport {
|
|
5
|
-
"mappings": "aAMA,IAAAA,
|
|
6
|
-
"names": ["import_touchUseCases", "deviceKey", "point", "controller", "timeoutSpy", "run", "customMs", "boom", "p", "assertion"]
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport type { TouchController } from \"@root/src/internal/core/TouchController\";\n\nimport {\n acceptBlindSigning,\n confirmAddressBookReview,\n continueToBlindSigning,\n enableBlindSigningSettings,\n enterMenu,\n exitMenu,\n mainButton,\n navigateNext,\n navigatePrevious,\n reject,\n secondaryButton,\n sign,\n tapLong,\n tapQuick,\n} from \"./touchUseCases\";\n\ndescribe(\"touchUsecases\", () => {\n const deviceKey = \"devA\";\n const point = { x: 50, y: 30 } as any;\n\n let controller: TouchController;\n\n beforeEach(() => {\n controller = {\n tap: vi.fn().mockResolvedValue(undefined),\n release: vi.fn().mockResolvedValue(undefined),\n tapAndRelease: vi.fn().mockResolvedValue(undefined),\n } as unknown as TouchController;\n vi.restoreAllMocks();\n vi.useRealTimers();\n });\n\n it(\"tapQuick calls tapAndRelease with the same deviceKey and point\", async () => {\n const quick = tapQuick(controller, deviceKey);\n await quick(point);\n\n expect(controller.tapAndRelease).toHaveBeenCalledTimes(1);\n expect(controller.tapAndRelease).toHaveBeenCalledWith(deviceKey, point);\n expect(controller.tap).not.toHaveBeenCalled();\n expect(controller.release).not.toHaveBeenCalled();\n });\n\n it(\"tapLong taps, waits default timeout, then releases\", async () => {\n vi.useFakeTimers();\n const timeoutSpy = vi.spyOn(globalThis, \"setTimeout\");\n\n const longTap = tapLong(controller, deviceKey);\n const run = longTap(point);\n\n await Promise.resolve();\n\n expect(controller.tap).toHaveBeenCalledTimes(1);\n expect(controller.tap).toHaveBeenCalledWith(deviceKey, point);\n expect(timeoutSpy).toHaveBeenCalledTimes(1);\n expect(timeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 5000);\n expect(controller.release).not.toHaveBeenCalled();\n\n // let the 5s timer elapse\n await vi.advanceTimersByTimeAsync(5000);\n await run;\n\n expect(controller.release).toHaveBeenCalledTimes(1);\n expect(controller.release).toHaveBeenCalledWith(deviceKey, point);\n });\n\n it(\"tapLong uses the provided delayMs value\", async () => {\n vi.useFakeTimers();\n const timeoutSpy = vi.spyOn(globalThis, \"setTimeout\");\n\n const customMs = 1234;\n const longTap = tapLong(controller, deviceKey);\n const run = longTap(point, customMs);\n\n await Promise.resolve();\n\n expect(controller.tap).toHaveBeenCalledTimes(1);\n expect(controller.tap).toHaveBeenCalledWith(deviceKey, point);\n expect(timeoutSpy).toHaveBeenCalledTimes(1);\n expect(timeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), customMs);\n expect(controller.release).not.toHaveBeenCalled();\n\n // advance exactly customMs and ensure release happens then\n await vi.advanceTimersByTimeAsync(customMs);\n await run;\n\n expect(controller.release).toHaveBeenCalledTimes(1);\n expect(controller.release).toHaveBeenCalledWith(deviceKey, point);\n });\n\n it(\"tapLong propagates error if tap() rejects (no release)\", async () => {\n vi.useFakeTimers();\n\n const boom = new Error(\"tap failed\");\n (controller.tap as any).mockRejectedValueOnce(boom);\n\n const longTap = tapLong(controller, deviceKey);\n const p = longTap(point);\n\n // attach rejection handler immediately\n await expect(p).rejects.toThrow(\"tap failed\");\n expect(controller.release).not.toHaveBeenCalled();\n });\n\n it(\"tapLong propagates error if release() rejects\", async () => {\n vi.useFakeTimers();\n\n const boom = new Error(\"release failed\");\n (controller.release as any).mockRejectedValueOnce(boom);\n\n const p = tapLong(controller, deviceKey)(point);\n\n const assertion = expect(p).rejects.toThrow(\"release failed\");\n\n await Promise.resolve();\n await vi.advanceTimersByTimeAsync(5000);\n\n await assertion;\n\n expect(controller.tap).toHaveBeenCalledTimes(1);\n expect(controller.release).toHaveBeenCalledTimes(1);\n });\n\n describe(\"enableBlindSigningSettings\", () => {\n it.each([\n [\"stax\", { x: 88, y: 51 }],\n [\"flex\", { x: 88, y: 58 }],\n [\"apex\", { x: 88, y: 58 }],\n ] as const)(\n \"taps the blind-signing toggle at the %s coordinates\",\n async (key, expected) => {\n await enableBlindSigningSettings(controller, key)();\n\n expect(controller.tapAndRelease).toHaveBeenCalledTimes(1);\n expect(controller.tapAndRelease).toHaveBeenCalledWith(key, expected);\n },\n );\n\n it(\"falls back to default coordinates for an unknown device key\", async () => {\n const unknownKey = \"unknown\";\n await enableBlindSigningSettings(controller, unknownKey)();\n\n expect(controller.tapAndRelease).toHaveBeenCalledTimes(1);\n expect(controller.tapAndRelease).toHaveBeenCalledWith(unknownKey, {\n x: 88,\n y: 51,\n });\n });\n });\n\n describe(\"fixed-coordinate taps\", () => {\n it.each([\n [\"reject\", reject, { x: 20, y: 90 }],\n [\"navigateNext\", navigateNext, { x: 90, y: 90 }],\n [\"navigatePrevious\", navigatePrevious, { x: 45, y: 90 }],\n [\"mainButton\", mainButton, { x: 50, y: 80 }],\n [\"secondaryButton\", secondaryButton, { x: 50, y: 90 }],\n [\"enterMenu\", enterMenu, { x: 85, y: 8 }],\n [\"exitMenu\", exitMenu, { x: 10, y: 4 }],\n [\"continueToBlindSigning\", continueToBlindSigning, { x: 50, y: 94 }],\n [\"acceptBlindSigning\", acceptBlindSigning, { x: 50, y: 94 }],\n ] as const)(\"%s taps %o\", async (_name, useCase, expected) => {\n await useCase(controller, deviceKey)();\n\n expect(controller.tapAndRelease).toHaveBeenCalledTimes(1);\n expect(controller.tapAndRelease).toHaveBeenCalledWith(\n deviceKey,\n expected,\n );\n });\n });\n\n describe(\"sign\", () => {\n const HOLD_TO_SIGN = { x: 85, y: 80 };\n\n it(\"holds the sign button for the default 5s\", async () => {\n vi.useFakeTimers();\n const timeoutSpy = vi.spyOn(globalThis, \"setTimeout\");\n\n const run = sign(controller, deviceKey)();\n await Promise.resolve();\n\n expect(controller.tap).toHaveBeenCalledWith(deviceKey, HOLD_TO_SIGN);\n expect(timeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 5000);\n\n await vi.advanceTimersByTimeAsync(5000);\n await run;\n\n expect(controller.release).toHaveBeenCalledWith(deviceKey, HOLD_TO_SIGN);\n });\n\n it(\"holds the sign button for the provided delay\", async () => {\n vi.useFakeTimers();\n const timeoutSpy = vi.spyOn(globalThis, \"setTimeout\");\n\n const customMs = 250;\n const run = sign(controller, deviceKey)(customMs);\n await Promise.resolve();\n\n expect(timeoutSpy).toHaveBeenLastCalledWith(\n expect.any(Function),\n customMs,\n );\n\n await vi.advanceTimersByTimeAsync(customMs);\n await run;\n\n expect(controller.release).toHaveBeenCalledTimes(1);\n });\n });\n\n describe(\"confirmAddressBookReview\", () => {\n // The Address Book review puts its Confirm button above the page footer,\n // so these coordinates are measured per model rather than shared with\n // mainButton/secondaryButton.\n it.each([\n [\"stax\", { x: 50, y: 77 }],\n [\"flex\", { x: 50, y: 72 }],\n ] as const)(\n \"taps the Confirm button at the %s coordinates\",\n async (key, expected) => {\n await confirmAddressBookReview(controller, key)();\n\n expect(controller.tapAndRelease).toHaveBeenCalledTimes(1);\n expect(controller.tapAndRelease).toHaveBeenCalledWith(key, expected);\n },\n );\n\n it(\"falls back to Flex coordinates for an unmeasured device key\", async () => {\n const unknownKey = \"apex\";\n await confirmAddressBookReview(controller, unknownKey)();\n\n expect(controller.tapAndRelease).toHaveBeenCalledTimes(1);\n expect(controller.tapAndRelease).toHaveBeenCalledWith(unknownKey, {\n x: 50,\n y: 72,\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAMA,IAAAA,EAeO,2BAEP,SAAS,gBAAiB,IAAM,CAC9B,MAAMC,EAAY,OACZC,EAAQ,CAAE,EAAG,GAAI,EAAG,EAAG,EAE7B,IAAIC,E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B,CAAC,EACxD,OAAOA,EAAW,aAAa,EAAE,qBAAqBO,EAAKC,CAAQ,CACrE,CACF,EAEA,GAAG,8DAA+D,SAAY,CAC5E,MAAMC,EAAa,OACnB,QAAM,4BAAyBT,EAAYS,CAAU,EAAE,EAEvD,OAAOT,EAAW,aAAa,EAAE,sBAAsB,CAAC,EACxD,OAAOA,EAAW,aAAa,EAAE,qBAAqBS,EAAY,CAChE,EAAG,GACH,EAAG,EACL,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_touchUseCases", "deviceKey", "point", "controller", "timeoutSpy", "run", "customMs", "boom", "p", "assertion", "key", "expected", "unknownKey", "_name", "useCase", "HOLD_TO_SIGN"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@ledgerhq/device-management-kit": "
|
|
4
|
-
"@sentry/minimal": "catalog:"
|
|
5
|
-
"axios": "catalog:"
|
|
3
|
+
"@ledgerhq/device-management-kit": "^1.11.0",
|
|
4
|
+
"@sentry/minimal": "catalog:"
|
|
6
5
|
},
|
|
7
6
|
"devDependencies": {
|
|
8
7
|
"@ledgerhq/eslint-config-dsdk": "workspace:^",
|
|
@@ -30,7 +29,7 @@
|
|
|
30
29
|
"license": "Apache-2.0",
|
|
31
30
|
"name": "@ledgerhq/speculos-device-controller",
|
|
32
31
|
"peerDependencies": {
|
|
33
|
-
"@ledgerhq/device-management-kit": "
|
|
32
|
+
"@ledgerhq/device-management-kit": "^1.11.0"
|
|
34
33
|
},
|
|
35
34
|
"private": false,
|
|
36
35
|
"repository": {
|
|
@@ -53,5 +52,5 @@
|
|
|
53
52
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
54
53
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
55
54
|
},
|
|
56
|
-
"version": "0.
|
|
55
|
+
"version": "0.4.0"
|
|
57
56
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DEFAULT_SCREENS as a}from"../internal/config/defaultScreens";import{createDefaultControllers as l}from"../../src/internal/di";import{pressButtons as
|
|
1
|
+
import{DEFAULT_SCREENS as a}from"../internal/config/defaultScreens";import{createDefaultControllers as l}from"../../src/internal/di";import{pressButtons as d,pressSequence as u}from"../../src/internal/use-cases/buttonUseCases";import{acceptBlindSigning as m,confirmAddressBookReview as p,continueToBlindSigning as v,enableBlindSigningSettings as g,enterMenu as B,exitMenu as P,mainButton as C,navigateNext as S,navigatePrevious as b,reject as y,secondaryButton as f,sign as x,tapLong as D,tapQuick as F}from"../../src/internal/use-cases/touchUseCases";const R=(r,o={})=>{const s={screens:o.screens??a,timeoutMs:o.timeoutMs,clientHeader:o.clientHeader,bearerToken:o.bearerToken},{buttons:n,touch:t}=l(r,s),i=d(n);return{buttonFactory:()=>({press:e=>n.press(e),left:()=>i.left(),right:()=>i.right(),both:()=>i.both(),pressSequence:(e,c)=>u(n,e,c)}),tapFactory:e=>({tapQuick:F(t,e),tapLong:D(t,e),sign:x(t,e),reject:y(t,e),navigateNext:S(t,e),navigatePrevious:b(t,e),mainButton:C(t,e),secondaryButton:f(t,e),enterMenu:B(t,e),exitMenu:P(t,e),enableBlindSigningSettings:g(t,e),continueToBlindSigning:v(t,e),acceptBlindSigning:m(t,e),confirmAddressBookReview:p(t,e)})}};export{R as deviceControllerClientFactory};
|
|
2
2
|
//# sourceMappingURL=DeviceController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/DeviceController.ts"],
|
|
4
|
-
"sourcesContent": ["import { DEFAULT_SCREENS } from \"@internal/config/defaultScreens\";\nimport type { ButtonController } from \"@internal/core/ButtonController\";\nimport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n} from \"@internal/core/types\";\nimport { createDefaultControllers } from \"@root/src/internal/di\";\nimport {\n pressButtons,\n pressSequence,\n} from \"@root/src/internal/use-cases/buttonUseCases\";\nimport {\n mainButton,\n navigateNext,\n navigatePrevious,\n reject,\n secondaryButton,\n sign,\n tapLong,\n tapQuick,\n} from \"@root/src/internal/use-cases/touchUseCases\";\n\nexport type ButtonFactory = () => ButtonController & {\n left(): Promise<void>;\n right(): Promise<void>;\n both(): Promise<void>;\n pressSequence(keys: ButtonKey[], delayMs?: number): Promise<void>;\n};\n\nexport type TapFactory = (deviceKey: string) => {\n tapQuick: (point: PercentCoordinates) => Promise<void>;\n tapLong: (point: PercentCoordinates, delayMs?: number) => Promise<void>;\n sign: (delayMs?: number) => Promise<void>;\n reject: () => Promise<void>;\n navigateNext: () => Promise<void>;\n navigatePrevious: () => Promise<void>;\n mainButton: () => Promise<void>;\n secondaryButton: () => Promise<void>;\n};\n\nexport type DeviceControllerClientFactory = (\n baseURL: string,\n opts?: {\n timeoutMs?: number;\n clientHeader?: string;\n screens?: DeviceScreens<string>;\n },\n) => DeviceControllerClient;\n\nexport type DeviceControllerClient = {\n buttonFactory: ButtonFactory;\n tapFactory: TapFactory;\n};\n\nexport const deviceControllerClientFactory: DeviceControllerClientFactory = (\n baseURL,\n opts = {},\n) => {\n const resolved: DeviceControllerOptions = {\n screens: opts.screens ?? DEFAULT_SCREENS,\n timeoutMs: opts.timeoutMs,\n clientHeader: opts.clientHeader,\n };\n\n const { buttons, touch } = createDefaultControllers(baseURL, resolved);\n const press = pressButtons(buttons);\n\n return {\n buttonFactory: () => ({\n press: (key) => buttons.press(key),\n left: () => press.left(),\n right: () => press.right(),\n both: () => press.both(),\n pressSequence: (keys, delayMs) => pressSequence(buttons, keys, delayMs),\n }),\n tapFactory: (key) => ({\n tapQuick: tapQuick(touch, key),\n tapLong: tapLong(touch, key),\n sign: sign(touch, key),\n reject: reject(touch, key),\n navigateNext: navigateNext(touch, key),\n navigatePrevious: navigatePrevious(touch, key),\n mainButton: mainButton(touch, key),\n secondaryButton: secondaryButton(touch, key),\n }),\n };\n};\n\nexport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n};\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,kCAQhC,OAAS,4BAAAC,MAAgC,wBACzC,OACE,gBAAAC,EACA,iBAAAC,MACK,8CACP,OACE,cAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,UAAAC,EACA,mBAAAC,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,MACK,
|
|
6
|
-
"names": ["DEFAULT_SCREENS", "createDefaultControllers", "pressButtons", "pressSequence", "mainButton", "navigateNext", "navigatePrevious", "reject", "secondaryButton", "sign", "tapLong", "tapQuick", "deviceControllerClientFactory", "baseURL", "opts", "resolved", "buttons", "touch", "press", "key", "keys", "delayMs"]
|
|
4
|
+
"sourcesContent": ["import { DEFAULT_SCREENS } from \"@internal/config/defaultScreens\";\nimport type { ButtonController } from \"@internal/core/ButtonController\";\nimport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n} from \"@internal/core/types\";\nimport { createDefaultControllers } from \"@root/src/internal/di\";\nimport {\n pressButtons,\n pressSequence,\n} from \"@root/src/internal/use-cases/buttonUseCases\";\nimport {\n acceptBlindSigning,\n confirmAddressBookReview,\n continueToBlindSigning,\n enableBlindSigningSettings,\n enterMenu,\n exitMenu,\n mainButton,\n navigateNext,\n navigatePrevious,\n reject,\n secondaryButton,\n sign,\n tapLong,\n tapQuick,\n} from \"@root/src/internal/use-cases/touchUseCases\";\n\nexport type ButtonFactory = () => ButtonController & {\n left(): Promise<void>;\n right(): Promise<void>;\n both(): Promise<void>;\n pressSequence(keys: ButtonKey[], delayMs?: number): Promise<void>;\n};\n\nexport type TapFactory = (deviceKey: string) => {\n tapQuick: (point: PercentCoordinates) => Promise<void>;\n tapLong: (point: PercentCoordinates, delayMs?: number) => Promise<void>;\n sign: (delayMs?: number) => Promise<void>;\n reject: () => Promise<void>;\n navigateNext: () => Promise<void>;\n navigatePrevious: () => Promise<void>;\n mainButton: () => Promise<void>;\n secondaryButton: () => Promise<void>;\n enterMenu: () => Promise<void>;\n exitMenu: () => Promise<void>;\n enableBlindSigningSettings: () => Promise<void>;\n continueToBlindSigning: () => Promise<void>;\n acceptBlindSigning: () => Promise<void>;\n confirmAddressBookReview: () => Promise<void>;\n};\n\nexport type DeviceControllerClientFactory = (\n baseURL: string,\n opts?: {\n timeoutMs?: number;\n clientHeader?: string;\n bearerToken?: string;\n screens?: DeviceScreens<string>;\n },\n) => DeviceControllerClient;\n\nexport type DeviceControllerClient = {\n buttonFactory: ButtonFactory;\n tapFactory: TapFactory;\n};\n\nexport const deviceControllerClientFactory: DeviceControllerClientFactory = (\n baseURL,\n opts = {},\n) => {\n const resolved: DeviceControllerOptions = {\n screens: opts.screens ?? DEFAULT_SCREENS,\n timeoutMs: opts.timeoutMs,\n clientHeader: opts.clientHeader,\n bearerToken: opts.bearerToken,\n };\n\n const { buttons, touch } = createDefaultControllers(baseURL, resolved);\n const press = pressButtons(buttons);\n\n return {\n buttonFactory: () => ({\n press: (key) => buttons.press(key),\n left: () => press.left(),\n right: () => press.right(),\n both: () => press.both(),\n pressSequence: (keys, delayMs) => pressSequence(buttons, keys, delayMs),\n }),\n tapFactory: (key) => ({\n tapQuick: tapQuick(touch, key),\n tapLong: tapLong(touch, key),\n sign: sign(touch, key),\n reject: reject(touch, key),\n navigateNext: navigateNext(touch, key),\n navigatePrevious: navigatePrevious(touch, key),\n mainButton: mainButton(touch, key),\n secondaryButton: secondaryButton(touch, key),\n enterMenu: enterMenu(touch, key),\n exitMenu: exitMenu(touch, key),\n enableBlindSigningSettings: enableBlindSigningSettings(touch, key),\n continueToBlindSigning: continueToBlindSigning(touch, key),\n acceptBlindSigning: acceptBlindSigning(touch, key),\n confirmAddressBookReview: confirmAddressBookReview(touch, key),\n }),\n };\n};\n\nexport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,kCAQhC,OAAS,4BAAAC,MAAgC,wBACzC,OACE,gBAAAC,EACA,iBAAAC,MACK,8CACP,OACE,sBAAAC,EACA,4BAAAC,EACA,0BAAAC,EACA,8BAAAC,EACA,aAAAC,EACA,YAAAC,EACA,cAAAC,EACA,gBAAAC,EACA,oBAAAC,EACA,UAAAC,EACA,mBAAAC,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,MACK,6CAyCA,MAAMC,EAA+D,CAC1EC,EACAC,EAAO,CAAC,IACL,CACH,MAAMC,EAAoC,CACxC,QAASD,EAAK,SAAWpB,EACzB,UAAWoB,EAAK,UAChB,aAAcA,EAAK,aACnB,YAAaA,EAAK,WACpB,EAEM,CAAE,QAAAE,EAAS,MAAAC,CAAM,EAAItB,EAAyBkB,EAASE,CAAQ,EAC/DG,EAAQtB,EAAaoB,CAAO,EAElC,MAAO,CACL,cAAe,KAAO,CACpB,MAAQG,GAAQH,EAAQ,MAAMG,CAAG,EACjC,KAAM,IAAMD,EAAM,KAAK,EACvB,MAAO,IAAMA,EAAM,MAAM,EACzB,KAAM,IAAMA,EAAM,KAAK,EACvB,cAAe,CAACE,EAAMC,IAAYxB,EAAcmB,EAASI,EAAMC,CAAO,CACxE,GACA,WAAaF,IAAS,CACpB,SAAUR,EAASM,EAAOE,CAAG,EAC7B,QAAST,EAAQO,EAAOE,CAAG,EAC3B,KAAMV,EAAKQ,EAAOE,CAAG,EACrB,OAAQZ,EAAOU,EAAOE,CAAG,EACzB,aAAcd,EAAaY,EAAOE,CAAG,EACrC,iBAAkBb,EAAiBW,EAAOE,CAAG,EAC7C,WAAYf,EAAWa,EAAOE,CAAG,EACjC,gBAAiBX,EAAgBS,EAAOE,CAAG,EAC3C,UAAWjB,EAAUe,EAAOE,CAAG,EAC/B,SAAUhB,EAASc,EAAOE,CAAG,EAC7B,2BAA4BlB,EAA2BgB,EAAOE,CAAG,EACjE,uBAAwBnB,EAAuBiB,EAAOE,CAAG,EACzD,mBAAoBrB,EAAmBmB,EAAOE,CAAG,EACjD,yBAA0BpB,EAAyBkB,EAAOE,CAAG,CAC/D,EACF,CACF",
|
|
6
|
+
"names": ["DEFAULT_SCREENS", "createDefaultControllers", "pressButtons", "pressSequence", "acceptBlindSigning", "confirmAddressBookReview", "continueToBlindSigning", "enableBlindSigningSettings", "enterMenu", "exitMenu", "mainButton", "navigateNext", "navigatePrevious", "reject", "secondaryButton", "sign", "tapLong", "tapQuick", "deviceControllerClientFactory", "baseURL", "opts", "resolved", "buttons", "touch", "press", "key", "keys", "delayMs"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{deviceControllerClientFactory as o}from"./DeviceController";describe("deviceControllerClientFactory",()=>{it("returns a DeviceControllerdeviceClient with the expected shape",()=>{const e=o("http://localhost:0");expect(e).toBeDefined(),expect(e).toHaveProperty("buttonFactory"),expect(e).toHaveProperty("tapFactory");const t=e.buttonFactory();expect(typeof t.press).toBe("function"),expect(typeof t.left).toBe("function"),expect(typeof t.right).toBe("function"),expect(typeof t.both).toBe("function"),expect(typeof t.pressSequence).toBe("function");const c=e.tapFactory("flex");expect(typeof c.tapQuick).toBe("function"),expect(typeof c.tapLong).toBe("function")}),it("does not throw when created with custom options",()=>{const t=o("http://127.0.0.1:0",{clientHeader:"test-suite",timeoutMs:200,screens:{custom:{width:128,height:64},stax:{width:400,height:672}}});expect(t).toBeTruthy()}),it("creates independent instances (no accidental shared state)",()=>{const e=o("http://localhost:0"),t=o("http://localhost:0");expect(e).not.toBe(t),expect(e.buttonFactory().press).not.toBe(t.buttonFactory().press),expect(e.tapFactory("flex").tapQuick).not.toBe(t.tapFactory("flex").tapQuick)})});
|
|
1
|
+
import{deviceControllerClientFactory as o}from"./DeviceController";describe("deviceControllerClientFactory",()=>{it("returns a DeviceControllerdeviceClient with the expected shape",()=>{const e=o("http://localhost:0");expect(e).toBeDefined(),expect(e).toHaveProperty("buttonFactory"),expect(e).toHaveProperty("tapFactory");const t=e.buttonFactory();expect(typeof t.press).toBe("function"),expect(typeof t.left).toBe("function"),expect(typeof t.right).toBe("function"),expect(typeof t.both).toBe("function"),expect(typeof t.pressSequence).toBe("function");const c=e.tapFactory("flex");expect(typeof c.tapQuick).toBe("function"),expect(typeof c.tapLong).toBe("function")}),it("does not throw when created with custom options",()=>{const t=o("http://127.0.0.1:0",{clientHeader:"test-suite",timeoutMs:200,screens:{custom:{width:128,height:64},stax:{width:400,height:672}}});expect(t).toBeTruthy()}),it("creates independent instances (no accidental shared state)",()=>{const e=o("http://localhost:0"),t=o("http://localhost:0");expect(e).not.toBe(t),expect(e.buttonFactory().press).not.toBe(t.buttonFactory().press),expect(e.tapFactory("flex").tapQuick).not.toBe(t.tapFactory("flex").tapQuick)}),it("sends the bearer token with every request",async()=>{const e=vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}"));await o("http://localhost:0",{bearerToken:"session-token"}).buttonFactory().press("both"),expect(e).toHaveBeenCalledWith("http://localhost:0/button/both",expect.objectContaining({headers:expect.objectContaining({Authorization:"Bearer session-token"})})),e.mockRestore()})});
|
|
2
2
|
//# sourceMappingURL=DeviceController.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/DeviceController.test.ts"],
|
|
4
|
-
"sourcesContent": ["import type { DeviceScreens } from \"@internal/core/types\";\n\nimport { deviceControllerClientFactory } from \"./DeviceController\";\n\ndescribe(\"deviceControllerClientFactory\", () => {\n it(\"returns a DeviceControllerdeviceClient with the expected shape\", () => {\n const deviceClient = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(deviceClient).toBeDefined();\n expect(deviceClient).toHaveProperty(\"buttonFactory\");\n expect(deviceClient).toHaveProperty(\"tapFactory\");\n\n const deviceButtons = deviceClient.buttonFactory();\n\n // button surfaces\n expect(typeof deviceButtons.press).toBe(\"function\");\n expect(typeof deviceButtons.left).toBe(\"function\");\n expect(typeof deviceButtons.right).toBe(\"function\");\n expect(typeof deviceButtons.both).toBe(\"function\");\n expect(typeof deviceButtons.pressSequence).toBe(\"function\");\n\n const deviceTaps = deviceClient.tapFactory(\"flex\");\n\n // tap surfaces\n expect(typeof deviceTaps.tapQuick).toBe(\"function\");\n expect(typeof deviceTaps.tapLong).toBe(\"function\");\n });\n\n it(\"does not throw when created with custom options\", () => {\n const screens: DeviceScreens<string> = {\n custom: { width: 128, height: 64 },\n stax: { width: 400, height: 672 },\n };\n const deviceClient = deviceControllerClientFactory(\"http://127.0.0.1:0\", {\n clientHeader: \"test-suite\",\n timeoutMs: 200,\n screens,\n });\n expect(deviceClient).toBeTruthy();\n });\n\n it(\"creates independent instances (no accidental shared state)\", () => {\n const a = deviceControllerClientFactory(\"http://localhost:0\");\n const b = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(a).not.toBe(b);\n expect(a.buttonFactory().press).not.toBe(b.buttonFactory().press);\n expect(a.tapFactory(\"flex\").tapQuick).not.toBe(\n b.tapFactory(\"flex\").tapQuick,\n );\n });\n});\n"],
|
|
5
|
-
"mappings": "AAEA,OAAS,iCAAAA,MAAqC,qBAE9C,SAAS,gCAAiC,IAAM,CAC9C,GAAG,iEAAkE,IAAM,CACzE,MAAMC,EAAeD,EAA8B,oBAAoB,EAEvE,OAAOC,CAAY,EAAE,YAAY,EACjC,OAAOA,CAAY,EAAE,eAAe,eAAe,EACnD,OAAOA,CAAY,EAAE,eAAe,YAAY,EAEhD,MAAMC,EAAgBD,EAAa,cAAc,EAGjD,OAAO,OAAOC,EAAc,KAAK,EAAE,KAAK,UAAU,EAClD,OAAO,OAAOA,EAAc,IAAI,EAAE,KAAK,UAAU,EACjD,OAAO,OAAOA,EAAc,KAAK,EAAE,KAAK,UAAU,EAClD,OAAO,OAAOA,EAAc,IAAI,EAAE,KAAK,UAAU,EACjD,OAAO,OAAOA,EAAc,aAAa,EAAE,KAAK,UAAU,EAE1D,MAAMC,EAAaF,EAAa,WAAW,MAAM,EAGjD,OAAO,OAAOE,EAAW,QAAQ,EAAE,KAAK,UAAU,EAClD,OAAO,OAAOA,EAAW,OAAO,EAAE,KAAK,UAAU,CACnD,CAAC,EAED,GAAG,kDAAmD,IAAM,CAK1D,MAAMF,EAAeD,EAA8B,qBAAsB,CACvE,aAAc,aACd,UAAW,IACX,QAPqC,CACrC,OAAQ,CAAE,MAAO,IAAK,OAAQ,EAAG,EACjC,KAAM,CAAE,MAAO,IAAK,OAAQ,GAAI,CAClC,CAKA,CAAC,EACD,OAAOC,CAAY,EAAE,WAAW,CAClC,CAAC,EAED,GAAG,6DAA8D,IAAM,CACrE,MAAMG,EAAIJ,EAA8B,oBAAoB,EACtDK,EAAIL,EAA8B,oBAAoB,EAE5D,OAAOI,CAAC,EAAE,IAAI,KAAKC,CAAC,EACpB,OAAOD,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,KAAKC,EAAE,cAAc,EAAE,KAAK,EAChE,OAAOD,EAAE,WAAW,MAAM,EAAE,QAAQ,EAAE,IAAI,KACxCC,EAAE,WAAW,MAAM,EAAE,QACvB,CACF,CAAC,CACH,CAAC",
|
|
6
|
-
"names": ["deviceControllerClientFactory", "deviceClient", "deviceButtons", "deviceTaps", "a", "b"]
|
|
4
|
+
"sourcesContent": ["import type { DeviceScreens } from \"@internal/core/types\";\n\nimport { deviceControllerClientFactory } from \"./DeviceController\";\n\ndescribe(\"deviceControllerClientFactory\", () => {\n it(\"returns a DeviceControllerdeviceClient with the expected shape\", () => {\n const deviceClient = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(deviceClient).toBeDefined();\n expect(deviceClient).toHaveProperty(\"buttonFactory\");\n expect(deviceClient).toHaveProperty(\"tapFactory\");\n\n const deviceButtons = deviceClient.buttonFactory();\n\n // button surfaces\n expect(typeof deviceButtons.press).toBe(\"function\");\n expect(typeof deviceButtons.left).toBe(\"function\");\n expect(typeof deviceButtons.right).toBe(\"function\");\n expect(typeof deviceButtons.both).toBe(\"function\");\n expect(typeof deviceButtons.pressSequence).toBe(\"function\");\n\n const deviceTaps = deviceClient.tapFactory(\"flex\");\n\n // tap surfaces\n expect(typeof deviceTaps.tapQuick).toBe(\"function\");\n expect(typeof deviceTaps.tapLong).toBe(\"function\");\n });\n\n it(\"does not throw when created with custom options\", () => {\n const screens: DeviceScreens<string> = {\n custom: { width: 128, height: 64 },\n stax: { width: 400, height: 672 },\n };\n const deviceClient = deviceControllerClientFactory(\"http://127.0.0.1:0\", {\n clientHeader: \"test-suite\",\n timeoutMs: 200,\n screens,\n });\n expect(deviceClient).toBeTruthy();\n });\n\n it(\"creates independent instances (no accidental shared state)\", () => {\n const a = deviceControllerClientFactory(\"http://localhost:0\");\n const b = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(a).not.toBe(b);\n expect(a.buttonFactory().press).not.toBe(b.buttonFactory().press);\n expect(a.tapFactory(\"flex\").tapQuick).not.toBe(\n b.tapFactory(\"flex\").tapQuick,\n );\n });\n\n it(\"sends the bearer token with every request\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n const deviceClient = deviceControllerClientFactory(\"http://localhost:0\", {\n bearerToken: \"session-token\",\n });\n\n await deviceClient.buttonFactory().press(\"both\");\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"http://localhost:0/button/both\",\n expect.objectContaining({\n headers: expect.objectContaining({\n Authorization: \"Bearer session-token\",\n }),\n }),\n );\n fetchSpy.mockRestore();\n });\n});\n"],
|
|
5
|
+
"mappings": "AAEA,OAAS,iCAAAA,MAAqC,qBAE9C,SAAS,gCAAiC,IAAM,CAC9C,GAAG,iEAAkE,IAAM,CACzE,MAAMC,EAAeD,EAA8B,oBAAoB,EAEvE,OAAOC,CAAY,EAAE,YAAY,EACjC,OAAOA,CAAY,EAAE,eAA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AAM,MAAM,EAE/C,OAAOM,CAAQ,EAAE,qBACf,iCACA,OAAO,iBAAiB,CACtB,QAAS,OAAO,iBAAiB,CAC/B,cAAe,sBACjB,CAAC,CACH,CAAC,CACH,EACAA,EAAS,YAAY,CACvB,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["deviceControllerClientFactory", "deviceClient", "deviceButtons", "deviceTaps", "a", "b", "fetchSpy"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultButtonController.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { ButtonController } from \"@internal/core/ButtonController\";\nimport {\n type ButtonKey,\n type HttpClient,\n SpeculosActions,\n} from \"@internal/core/types\";\n\nexport class DefaultButtonController implements ButtonController {\n constructor(private readonly client: HttpClient) {}\n\n async press(key: ButtonKey): Promise<void> {\n await this.client.post(`/button/${key}`, {\n action: SpeculosActions.PRESS_AND_RELEASE,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAGE,mBAAAA,MACK,uBAEA,MAAMC,CAAoD,CAC/D,YAA6BC,EAAoB,CAApB,YAAAA,CAAqB,CAElD,MAAM,MAAMC,EAA+B,CACzC,MAAM,KAAK,OAAO,KAAK,WAAWA,CAAG,GAAI,CACvC,OAAQH,EAAgB,iBAC1B,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["SpeculosActions", "DefaultButtonController", "client", "key"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DefaultButtonController as
|
|
1
|
+
import{DefaultButtonController as l}from"./DefaultButtonController";describe("DefaultButtonController",()=>{let e,n,o;beforeEach(()=>{e=vi.fn().mockResolvedValue(void 0),n={post:e},o=new l(n)});const r=["left","right","both"];it.each(r)("press(%s) posts expected payload",async t=>{await o.press(t),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith(`/button/${t}`,{action:"press-and-release"})}),it("propagates HTTP errors",async()=>{const t=new Error("oups");e.mockRejectedValueOnce(t),await expect(o.press("left")).rejects.toBe(t)})});
|
|
2
2
|
//# sourceMappingURL=DefaultButtonController.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultButtonController.test.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["DefaultButtonController", "postMock", "
|
|
4
|
+
"sourcesContent": ["import type { ButtonKey, HttpClient } from \"@internal/core/types\";\n\nimport { DefaultButtonController } from \"./DefaultButtonController\";\n\ndescribe(\"DefaultButtonController\", () => {\n let postMock: ReturnType<typeof vi.fn>;\n let httpClient: HttpClient;\n let controller: DefaultButtonController;\n\n beforeEach(() => {\n postMock = vi.fn().mockResolvedValue(undefined);\n httpClient = { post: postMock };\n controller = new DefaultButtonController(httpClient);\n });\n\n const keys: ButtonKey[] = [\"left\", \"right\", \"both\"];\n\n it.each<ButtonKey>(keys)(\n \"press(%s) posts expected payload\",\n async (key: ButtonKey) => {\n await controller.press(key);\n\n expect(postMock).toHaveBeenCalledTimes(1);\n expect(postMock).toHaveBeenCalledWith(`/button/${key}`, {\n action: \"press-and-release\",\n });\n },\n );\n\n it(\"propagates HTTP errors\", async () => {\n const error = new Error(\"oups\");\n postMock.mockRejectedValueOnce(error);\n\n await expect(controller.press(\"left\" as ButtonKey)).rejects.toBe(error);\n });\n});\n"],
|
|
5
|
+
"mappings": "AAEA,OAAS,2BAAAA,MAA+B,4BAExC,SAAS,0BAA2B,IAAM,CACxC,IAAIC,EACAC,EACAC,EAEJ,WAAW,IAAM,CACfF,EAAW,GAAG,GAAG,EAAE,kBAAkB,MAAS,EAC9CC,EAAa,CAAE,KAAMD,CAAS,EAC9BE,EAAa,IAAIH,EAAwBE,CAAU,CACrD,CAAC,EAED,MAAME,EAAoB,CAAC,OAAQ,QAAS,MAAM,EAElD,GAAG,KAAgBA,CAAI,EACrB,mCACA,MAAOC,GAAmB,CACxB,MAAMF,EAAW,MAAME,CAAG,EAE1B,OAAOJ,CAAQ,EAAE,sBAAsB,CAAC,EACxC,OAAOA,CAAQ,EAAE,qBAAqB,WAAWI,CAAG,GAAI,CACtD,OAAQ,mBACV,CAAC,CACH,CACF,EAEA,GAAG,yBAA0B,SAAY,CACvC,MAAMC,EAAQ,IAAI,MAAM,MAAM,EAC9BL,EAAS,sBAAsBK,CAAK,EAEpC,MAAM,OAAOH,EAAW,MAAM,MAAmB,CAAC,EAAE,QAAQ,KAAKG,CAAK,CACxE,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DefaultButtonController", "postMock", "httpClient", "controller", "keys", "key", "error"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{SpeculosActions as
|
|
1
|
+
import{SpeculosActions as i}from"../core/types";class a{constructor(e,t){this.client=e;this.axes=t}assertPercentPoint({x:e,y:t}){const o=n=>Number.isFinite(n)&&n>=0&&n<=100;if(!o(e)||!o(t))throw new Error(`[Touch] percent values must be within 0\u2013100. Received x=${e}, y=${t}`)}toAbs(e,t){const o=this.axes[e];if(!o){const n=Object.keys(this.axes);throw new Error(`[Touch] Unknown device key "${String(e)}". Known keys: ${n.join(", ")||"<none>"}`)}return this.assertPercentPoint(t),o.xy(t.x,t.y)}async tapAndRelease(e,t){const o=this.toAbs(e,t);await this.client.post("/finger",{action:i.PRESS_AND_RELEASE,...o})}async tap(e,t){const o=this.toAbs(e,t);await this.client.post("/finger",{action:i.PRESS,...o})}async release(e,t){const o=this.toAbs(e,t);await this.client.post("/finger",{action:i.RELEASE,...o})}}export{a as DefaultTouchController};
|
|
2
2
|
//# sourceMappingURL=DefaultTouchController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultTouchController.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import {\n type HttpClient,\n type PercentCoordinates,\n SpeculosActions,\n} from \"@internal/core/types\";\nimport type { AxisMap } from \"@internal/utils/axisClamp\";\nimport type { TouchController } from \"@root/src/internal/core/TouchController\";\n\nexport class DefaultTouchController<K extends string>\n implements TouchController<K>\n{\n constructor(\n private readonly client: HttpClient,\n private readonly axes: AxisMap<K>,\n ) {}\n\n private assertPercentPoint({ x, y }: PercentCoordinates): void {\n const inRange = (v: number) => Number.isFinite(v) && v >= 0 && v <= 100;\n if (!inRange(x) || !inRange(y)) {\n throw new Error(\n `[Touch] percent values must be within 0\u2013100. Received x=${x}, y=${y}`,\n );\n }\n }\n\n private toAbs(deviceKey: K, p: PercentCoordinates) {\n const axis = this.axes[deviceKey];\n if (!axis) {\n const known = Object.keys(this.axes as Record<string, unknown>);\n throw new Error(\n `[Touch] Unknown device key \"${String(deviceKey)}\". Known keys: ${known.join(\", \") || \"<none>\"}`,\n );\n }\n this.assertPercentPoint(p);\n return axis.xy(p.x, p.y);\n }\n\n async tapAndRelease(deviceKey: K, point: PercentCoordinates): Promise<void> {\n const abs = this.toAbs(deviceKey, point);\n await this.client.post(`/finger`, {\n action: SpeculosActions.PRESS_AND_RELEASE,\n ...abs,\n });\n }\n\n async tap(deviceKey: K, point: PercentCoordinates): Promise<void> {\n const abs = this.toAbs(deviceKey, point);\n await this.client.post(`/finger`, {\n action: SpeculosActions.PRESS,\n ...abs,\n });\n }\n\n async release(deviceKey: K, point: PercentCoordinates): Promise<void> {\n const abs = this.toAbs(deviceKey, point);\n await this.client.post(`/finger`, {\n action: SpeculosActions.RELEASE,\n ...abs,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAGE,mBAAAA,MACK,uBAIA,MAAMC,CAEb,CACE,YACmBC,EACAC,EACjB,CAFiB,YAAAD,EACA,UAAAC,CAChB,CAEK,mBAAmB,CAAE,EAAAC,EAAG,EAAAC,CAAE,EAA6B,CAC7D,MAAMC,EAAWC,GAAc,OAAO,SAASA,CAAC,GAAKA,GAAK,GAAKA,GAAK,IACpE,GAAI,CAACD,EAAQF,CAAC,GAAK,CAACE,EAAQD,CAAC,EAC3B,MAAM,IAAI,MACR,gEAA2DD,CAAC,OAAOC,CAAC,EACtE,CAEJ,CAEQ,MAAMG,EAAcC,EAAuB,CACjD,MAAMC,EAAO,KAAK,KAAKF,CAAS,EAChC,GAAI,CAACE,EAAM,CACT,MAAMC,EAAQ,OAAO,KAAK,KAAK,IAA+B,EAC9D,MAAM,IAAI,MACR,+BAA+B,OAAOH,CAAS,CAAC,kBAAkBG,EAAM,KAAK,IAAI,GAAK,QAAQ,EAChG,CACF,CACA,YAAK,mBAAmBF,CAAC,EAClBC,EAAK,GAAGD,EAAE,EAAGA,EAAE,CAAC,CACzB,CAEA,MAAM,cAAcD,EAAcI,EAA0C,CAC1E,MAAMC,EAAM,KAAK,MAAML,EAAWI,CAAK,EACvC,MAAM,KAAK,OAAO,KAAK,UAAW,CAChC,OAAQZ,EAAgB,kBACxB,GAAGa,CACL,CAAC,CACH,CAEA,MAAM,IAAIL,EAAcI,EAA0C,CAChE,MAAMC,EAAM,KAAK,MAAML,EAAWI,CAAK,EACvC,MAAM,KAAK,OAAO,KAAK,UAAW,CAChC,OAAQZ,EAAgB,MACxB,GAAGa,CACL,CAAC,CACH,CAEA,MAAM,QAAQL,EAAcI,EAA0C,CACpE,MAAMC,EAAM,KAAK,MAAML,EAAWI,CAAK,EACvC,MAAM,KAAK,OAAO,KAAK,UAAW,CAChC,OAAQZ,EAAgB,QACxB,GAAGa,CACL,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["SpeculosActions", "DefaultTouchController", "client", "axes", "x", "y", "inRange", "v", "deviceKey", "p", "axis", "known", "point", "abs"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DefaultTouchController as l}from"./DefaultTouchController";describe("DefaultTouchController",()=>{let e,s;const o={xy:vi.fn((
|
|
1
|
+
import{DefaultTouchController as l}from"./DefaultTouchController";describe("DefaultTouchController",()=>{let e,s;const o={xy:vi.fn((a,i)=>({x:Math.round(a*10),y:Math.round(i*20)}))},r={xy:vi.fn((a,i)=>({x:Math.round(100+a),y:Math.round(200+i)}))};let c,n;beforeEach(()=>{e=vi.fn().mockResolvedValue(void 0),s={post:e},o.xy.mockClear(),r.xy.mockClear(),c={devA:o,devB:r},n=new l(s,c)});const t={x:12,y:45};it("tapAndRelease: converts percent to absolute via axes and POSTs expected body",async()=>{await n.tapAndRelease("devA",t),expect(o.xy).toHaveBeenCalledTimes(1),expect(o.xy).toHaveBeenCalledWith(t.x,t.y);const a=o.xy.mock.results[0].value;expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith("/finger",{action:"press-and-release",...a})}),it("tap: converts via axes and POSTs action 'press'",async()=>{await n.tap("devB",t),expect(r.xy).toHaveBeenCalledWith(t.x,t.y);const a=r.xy.mock.results[0]?.value;expect(e).toHaveBeenCalledWith("/finger",{action:"press",...a})}),it("release: converts via axes and POSTs action 'release'",async()=>{await n.release("devA",t);const a=o.xy.mock.results[0].value;expect(e).toHaveBeenCalledWith("/finger",{action:"release",...a})}),it("throws an error when device key is unknown",async()=>{await expect(n.tap("unknownDevice",t)).rejects.toThrow(/\[Touch] Unknown device key "unknownDevice".*Known keys: devA, devB/),expect(e).not.toHaveBeenCalled()}),it("propagates HTTP errors",async()=>{const a=new Error("backend down");e.mockRejectedValueOnce(a),await expect(n.tapAndRelease("devA",t)).rejects.toBe(a)})});describe("percent validation",()=>{let e,s,o;const r={xy:vi.fn((n,t)=>({x:n,y:t}))},c={devA:r};beforeEach(()=>{s=vi.fn().mockResolvedValue(void 0),o={post:s},r.xy.mockClear(),e=new l(o,c)}),it("accepts boundary values 0 and 100",async()=>{await e.tapAndRelease("devA",{x:0,y:100}),await e.tap("devA",{x:100,y:0}),await e.release("devA",{x:50,y:99}),expect(s).toHaveBeenCalledTimes(3)}),it("rejects values outside [0, 100], non-finite, negative and non-integer",async()=>{const n=[{x:140,y:50},{x:-1,y:50},{x:50,y:120},{x:50,y:-.01}];for(const t of n)await expect(e.tapAndRelease("devA",t)).rejects.toThrow();expect(s).not.toHaveBeenCalled()}),it("rejects NaN or non-finite values",async()=>{const n=[{x:Number.NaN,y:50},{x:50,y:Number.NaN},{x:Number.POSITIVE_INFINITY,y:10},{x:10,y:Number.NEGATIVE_INFINITY}];for(const t of n)await expect(e.tap("devA",t)).rejects.toThrow(/percent/i);expect(s).not.toHaveBeenCalled()})});
|
|
2
2
|
//# sourceMappingURL=DefaultTouchController.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultTouchController.test.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport type {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["DefaultTouchController", "postMock", "
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport type { HttpClient, PercentCoordinates } from \"../core/types\";\nimport { DefaultTouchController } from \"./DefaultTouchController\";\n\ndescribe(\"DefaultTouchController\", () => {\n let postMock: ReturnType<typeof vi.fn>;\n let httpClient: HttpClient;\n\n const axisA = {\n xy: vi.fn((xPct: number, yPct: number) => ({\n x: Math.round(xPct * 10),\n y: Math.round(yPct * 20),\n })),\n };\n const axisB = {\n xy: vi.fn((xPct: number, yPct: number) => ({\n x: Math.round(100 + xPct),\n y: Math.round(200 + yPct),\n })),\n };\n let axesFake: Record<\n string,\n { xy: (x: number, y: number) => { x: number; y: number } }\n >;\n\n let controller: DefaultTouchController<string>;\n\n beforeEach(() => {\n postMock = vi.fn().mockResolvedValue(undefined);\n httpClient = { post: postMock };\n\n axisA.xy.mockClear();\n axisB.xy.mockClear();\n\n axesFake = { devA: axisA, devB: axisB };\n controller = new DefaultTouchController(httpClient, axesFake as any);\n });\n\n const point: PercentCoordinates = { x: 12, y: 45 };\n\n it(\"tapAndRelease: converts percent to absolute via axes and POSTs expected body\", async () => {\n await controller.tapAndRelease(\"devA\", point);\n\n expect(axisA.xy).toHaveBeenCalledTimes(1);\n expect(axisA.xy).toHaveBeenCalledWith(point.x, point.y);\n\n const expectedAbs = (axisA.xy.mock.results as any)[0].value;\n expect(postMock).toHaveBeenCalledTimes(1);\n expect(postMock).toHaveBeenCalledWith(\"/finger\", {\n action: \"press-and-release\",\n ...expectedAbs,\n });\n });\n\n it(\"tap: converts via axes and POSTs action 'press'\", async () => {\n await controller.tap(\"devB\", point);\n\n expect(axisB.xy).toHaveBeenCalledWith(point.x, point.y);\n const expectedAbs = axisB.xy.mock.results[0]?.value;\n\n expect(postMock).toHaveBeenCalledWith(\"/finger\", {\n action: \"press\",\n ...expectedAbs,\n });\n });\n\n it(\"release: converts via axes and POSTs action 'release'\", async () => {\n await controller.release(\"devA\", point);\n\n const expectedAbs = axisA.xy.mock.results[0]!.value;\n expect(postMock).toHaveBeenCalledWith(\"/finger\", {\n action: \"release\",\n ...expectedAbs,\n });\n });\n\n it(\"throws an error when device key is unknown\", async () => {\n await expect(controller.tap(\"unknownDevice\" as any, point)).rejects.toThrow(\n /\\[Touch] Unknown device key \"unknownDevice\".*Known keys: devA, devB/,\n );\n expect(postMock).not.toHaveBeenCalled();\n });\n\n it(\"propagates HTTP errors\", async () => {\n const boom = new Error(\"backend down\");\n postMock.mockRejectedValueOnce(boom);\n\n await expect(controller.tapAndRelease(\"devA\", point)).rejects.toBe(boom);\n });\n});\n\ndescribe(\"percent validation\", () => {\n let controller: DefaultTouchController<string>;\n let postMock: ReturnType<typeof vi.fn>;\n let httpClient: HttpClient;\n\n const axis = {\n xy: vi.fn((xPct: number, yPct: number) => ({ x: xPct, y: yPct })),\n };\n const axesFake = { devA: axis };\n\n beforeEach(() => {\n postMock = vi.fn().mockResolvedValue(undefined);\n httpClient = { post: postMock };\n axis.xy.mockClear();\n controller = new DefaultTouchController(httpClient, axesFake as any);\n });\n\n it(\"accepts boundary values 0 and 100\", async () => {\n await controller.tapAndRelease(\"devA\", { x: 0, y: 100 });\n await controller.tap(\"devA\", { x: 100, y: 0 });\n await controller.release(\"devA\", { x: 50, y: 99 });\n\n // should have sent 3 HTTP calls if all accepted\n expect(postMock).toHaveBeenCalledTimes(3);\n });\n\n it(\"rejects values outside [0, 100], non-finite, negative and non-integer\", async () => {\n const badPoints = [\n { x: 140, y: 50 },\n { x: -1, y: 50 },\n { x: 50, y: 120 },\n { x: 50, y: -0.01 },\n ];\n\n for (const p of badPoints) {\n await expect(\n controller.tapAndRelease(\"devA\", p as any),\n ).rejects.toThrow();\n }\n\n // no HTTP calls should be made for invalid input\n expect(postMock).not.toHaveBeenCalled();\n });\n\n it(\"rejects NaN or non-finite values\", async () => {\n const badPoints = [\n { x: Number.NaN, y: 50 },\n { x: 50, y: Number.NaN },\n { x: Number.POSITIVE_INFINITY, y: 10 },\n { x: 10, y: Number.NEGATIVE_INFINITY },\n ];\n\n for (const p of badPoints) {\n await expect(controller.tap(\"devA\", p as any)).rejects.toThrow(\n /percent/i,\n );\n }\n expect(postMock).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "AAKA,OAAS,0BAAAA,MAA8B,2BAEvC,SAAS,yBAA0B,IAAM,CACvC,IAAIC,EACAC,EAEJ,MAAMC,EAAQ,CACZ,GAAI,GAAG,GAAG,CAACC,EAAcC,KAAkB,CACzC,EAAG,KAAK,MAAMD,EAAO,EAAE,EACvB,EAAG,KAAK,MAAMC,EAAO,EAAE,CACzB,EAAE,CACJ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AE,EAAG,GAAI,EAAG,GAAI,EAChB,CAAE,EAAG,GAAI,EAAG,IAAM,CACpB,EAEA,UAAWC,KAAKD,EACd,MAAM,OACJL,EAAW,cAAc,OAAQM,CAAQ,CAC3C,EAAE,QAAQ,QAAQ,EAIpB,OAAOb,CAAQ,EAAE,IAAI,iBAAiB,CACxC,CAAC,EAED,GAAG,mCAAoC,SAAY,CACjD,MAAMY,EAAY,CAChB,CAAE,EAAG,OAAO,IAAK,EAAG,EAAG,EACvB,CAAE,EAAG,GAAI,EAAG,OAAO,GAAI,EACvB,CAAE,EAAG,OAAO,kBAAmB,EAAG,EAAG,EACrC,CAAE,EAAG,GAAI,EAAG,OAAO,iBAAkB,CACvC,EAEA,UAAWC,KAAKD,EACd,MAAM,OAAOL,EAAW,IAAI,OAAQM,CAAQ,CAAC,EAAE,QAAQ,QACrD,UACF,EAEF,OAAOb,CAAQ,EAAE,IAAI,iBAAiB,CACxC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DefaultTouchController", "postMock", "httpClient", "axisA", "xPct", "yPct", "axisB", "axesFake", "controller", "point", "expectedAbs", "boom", "axis", "badPoints", "p"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/core/types.ts"],
|
|
4
|
-
"sourcesContent": ["export type ButtonKey = \"left\" | \"right\" | \"both\";\n\nexport type ScreenSpec = Readonly<{ width: number; height: number }>;\n\nexport type DeviceScreens<K extends string = string> = Readonly<\n Record<K, ScreenSpec>\n>;\n\nexport type Range<\n N extends number,\n Acc extends number[] = [],\n> = Acc[\"length\"] extends N ? Acc[number] : Range<N, [...Acc, Acc[\"length\"]]>;\nexport type Percent = Range<101>;\n\nexport type PercentCoordinates = { x: Percent; y: Percent };\n\nexport type DeviceControllerOptions<K extends string = string> = {\n screens: DeviceScreens<K>;\n timeoutMs?: number;\n clientHeader?: string;\n};\n\nexport enum SpeculosActions {\n PRESS = \"press\",\n RELEASE = \"release\",\n PRESS_AND_RELEASE = \"press-and-release\",\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export type ButtonKey = \"left\" | \"right\" | \"both\";\n\nexport type ScreenSpec = Readonly<{ width: number; height: number }>;\n\nexport type DeviceScreens<K extends string = string> = Readonly<\n Record<K, ScreenSpec>\n>;\n\nexport type Range<\n N extends number,\n Acc extends number[] = [],\n> = Acc[\"length\"] extends N ? Acc[number] : Range<N, [...Acc, Acc[\"length\"]]>;\nexport type Percent = Range<101>;\n\nexport type PercentCoordinates = { x: Percent; y: Percent };\n\nexport type DeviceControllerOptions<K extends string = string> = {\n screens: DeviceScreens<K>;\n timeoutMs?: number;\n clientHeader?: string;\n bearerToken?: string;\n};\n\nexport interface HttpClient {\n post(url: string, data?: unknown): Promise<unknown>;\n}\n\nexport enum SpeculosActions {\n PRESS = \"press\",\n RELEASE = \"release\",\n PRESS_AND_RELEASE = \"press-and-release\",\n}\n"],
|
|
5
|
+
"mappings": "AA2BO,IAAKA,OACVA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,kBAAoB,oBAHVA,OAAA",
|
|
6
6
|
"names": ["SpeculosActions"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{DmkNetworkClient as a}from"@ledgerhq/device-management-kit";import{DefaultButtonController as p}from"./adapters/DefaultButtonController";import{DefaultTouchController as C}from"./adapters/DefaultTouchController";import{createAxes as m}from"./utils/axisClamp";function T(r,t){const e=t.timeoutMs??1500,n=new a({baseUrl:r,headers:{"X-Ledger-Client-Version":t.clientHeader??"ldmk-transport-speculos",...t.bearerToken?{Authorization:`Bearer ${t.bearerToken}`}:{}}}),o={async post(c,u){return n.post(c,u,{timeoutMs:e})}},l=m(t.screens),i=new p(o),s=new C(o,l);return{buttons:i,touch:s}}export{T as createDefaultControllers};
|
|
2
2
|
//# sourceMappingURL=di.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/di.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\n\nimport { DefaultButtonController } from \"@internal/adapters/DefaultButtonController\";\nimport { DefaultTouchController } from \"@internal/adapters/DefaultTouchController\";\nimport type { ButtonController } from \"@internal/core/ButtonController\";\nimport type { DeviceControllerOptions, HttpClient } from \"@internal/core/types\";\nimport { type AxisMap, createAxes } from \"@internal/utils/axisClamp\";\nimport type { TouchController } from \"@root/src/internal/core/TouchController\";\n\nexport type ControllersContainer = {\n buttons: ButtonController;\n touch: TouchController;\n};\n\nexport function createDefaultControllers(\n baseURL: string,\n opts: DeviceControllerOptions,\n): ControllersContainer {\n const timeoutMs = opts.timeoutMs ?? 1500;\n const client = new DmkNetworkClient({\n baseUrl: baseURL,\n headers: {\n \"X-Ledger-Client-Version\": opts.clientHeader ?? \"ldmk-transport-speculos\",\n ...(opts.bearerToken\n ? { Authorization: `Bearer ${opts.bearerToken}` }\n : {}),\n },\n });\n\n const http: HttpClient = {\n async post(url: string, data?: unknown): Promise<unknown> {\n return client.post(url, data, { timeoutMs });\n },\n };\n\n const axes: AxisMap = createAxes(opts.screens);\n\n const buttons: ButtonController = new DefaultButtonController(http);\n const touch: TouchController = new DefaultTouchController(http, axes);\n\n return { buttons, touch };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,oBAAAA,MAAwB,kCAEjC,OAAS,2BAAAC,MAA+B,6CACxC,OAAS,0BAAAC,MAA8B,4CAGvC,OAAuB,cAAAC,MAAkB,4BAQlC,SAASC,EACdC,EACAC,EACsB,CACtB,MAAMC,EAAYD,EAAK,WAAa,KAC9BE,EAAS,IAAIR,EAAiB,CAClC,QAASK,EACT,QAAS,CACP,0BAA2BC,EAAK,cAAgB,0BAChD,GAAIA,EAAK,YACL,CAAE,cAAe,UAAUA,EAAK,WAAW,EAAG,EAC9C,CAAC,CACP,CACF,CAAC,EAEKG,EAAmB,CACvB,MAAM,KAAKC,EAAaC,EAAkC,CACxD,OAAOH,EAAO,KAAKE,EAAKC,EAAM,CAAE,UAAAJ,CAAU,CAAC,CAC7C,CACF,EAEMK,EAAgBT,EAAWG,EAAK,OAAO,EAEvCO,EAA4B,IAAIZ,EAAwBQ,CAAI,EAC5DK,EAAyB,IAAIZ,EAAuBO,EAAMG,CAAI,EAEpE,MAAO,CAAE,QAAAC,EAAS,MAAAC,CAAM,CAC1B",
|
|
6
|
+
"names": ["DmkNetworkClient", "DefaultButtonController", "DefaultTouchController", "createAxes", "createDefaultControllers", "baseURL", "opts", "timeoutMs", "client", "http", "url", "data", "axes", "buttons", "touch"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{afterEach as i,describe as l,expect as e,it as a,vi as c}from"vitest";import{DefaultButtonController as r}from"./adapters/DefaultButtonController";import{DefaultTouchController as h}from"./adapters/DefaultTouchController";import{createDefaultControllers as s}from"./di";const n={flex:{width:128,height:64},stax:{width:400,height:672}};i(()=>{c.restoreAllMocks()});l("createDefaultControllers - fetch configuration",()=>{a("configures with custom timeout and header",async()=>{const t=c.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{buttons:o}=s("https://example.com/api",{screens:n,timeoutMs:2345,clientHeader:"test-client"});await o.press("left"),e(t).toHaveBeenCalledTimes(1),e(t).toHaveBeenCalledWith("https://example.com/api/button/left",e.objectContaining({method:"POST",headers:e.objectContaining({"X-Ledger-Client-Version":"test-client"})}))}),a("applies default timeout and client header when not provided",async()=>{const t=c.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{buttons:o}=s("https://localhost:1234",{screens:n});await o.press("left"),e(t).toHaveBeenCalledWith("https://localhost:1234/button/left",e.objectContaining({method:"POST",headers:e.objectContaining({"X-Ledger-Client-Version":"ldmk-transport-speculos"})}))}),a("sends the bearer token alongside the client header",async()=>{const t=c.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{touch:o}=s("https://localhost:1234",{screens:n,clientHeader:"test-client",bearerToken:"session-token"});await o.tap("stax",{x:50,y:50}),e(t).toHaveBeenCalledWith("https://localhost:1234/finger",e.objectContaining({headers:e.objectContaining({Authorization:"Bearer session-token","X-Ledger-Client-Version":"test-client"})}))})});l("createDefaultControllers - wiring",()=>{a("returns correct controller implementations",()=>{const{buttons:t,touch:o}=s("https://x",{screens:n});e(t).toBeInstanceOf(r),e(o).toBeInstanceOf(h),e(typeof t.press).toBe("function")}),a("creates fresh instances per invocation",()=>{const t=s("https://x",{screens:n}),o=s("https://x",{screens:n});e(t.buttons).not.toBe(o.buttons),e(t.touch).not.toBe(o.touch)}),a("button.press posts the correct payload",async()=>{const t=c.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{buttons:o}=s("https://x",{screens:n});await o.press("left"),e(t).toHaveBeenCalledWith("https://x/button/left",e.objectContaining({method:"POST",body:JSON.stringify({action:"press-and-release"})}))}),a("touch.tapAndRelease maps percent to absolute coords",async()=>{const t=c.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{touch:o}=s("https://x",{screens:n});await o.tapAndRelease("flex",{x:50,y:50}),e(t).toHaveBeenCalledWith("https://x/finger",e.objectContaining({method:"POST",body:JSON.stringify({action:"press-and-release",x:64,y:32})}))})});
|
|
2
2
|
//# sourceMappingURL=di.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/di.test.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\n\nimport { DefaultButtonController } from \"@internal/adapters/DefaultButtonController\";\nimport { DefaultTouchController } from \"@internal/adapters/DefaultTouchController\";\n\nimport { createDefaultControllers } from \"./di\";\n\nconst SCREENS = {\n flex: { width: 128, height: 64 },\n stax: { width: 400, height: 672 },\n} as const;\n\nafterEach(() => {\n vi.restoreAllMocks();\n});\n\ndescribe(\"createDefaultControllers - fetch configuration\", () => {\n it(\"configures with custom timeout and header\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { buttons } = createDefaultControllers(\"https://example.com/api\", {\n screens: SCREENS,\n timeoutMs: 2345,\n clientHeader: \"test-client\",\n });\n\n await buttons.press(\"left\");\n\n expect(fetchSpy).toHaveBeenCalledTimes(1);\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://example.com/api/button/left\",\n expect.objectContaining({\n method: \"POST\",\n headers: expect.objectContaining({\n \"X-Ledger-Client-Version\": \"test-client\",\n }),\n }),\n );\n });\n\n it(\"applies default timeout and client header when not provided\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { buttons } = createDefaultControllers(\"https://localhost:1234\", {\n screens: SCREENS,\n });\n\n await buttons.press(\"left\");\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://localhost:1234/button/left\",\n expect.objectContaining({\n method: \"POST\",\n headers: expect.objectContaining({\n \"X-Ledger-Client-Version\": \"ldmk-transport-speculos\",\n }),\n }),\n );\n });\n\n it(\"sends the bearer token alongside the client header\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { touch } = createDefaultControllers(\"https://localhost:1234\", {\n screens: SCREENS,\n clientHeader: \"test-client\",\n bearerToken: \"session-token\",\n });\n\n await touch.tap(\"stax\", { x: 50, y: 50 });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://localhost:1234/finger\",\n expect.objectContaining({\n headers: expect.objectContaining({\n Authorization: \"Bearer session-token\",\n \"X-Ledger-Client-Version\": \"test-client\",\n }),\n }),\n );\n });\n});\n\ndescribe(\"createDefaultControllers - wiring\", () => {\n it(\"returns correct controller implementations\", () => {\n const { buttons, touch } = createDefaultControllers(\"https://x\", {\n screens: SCREENS,\n });\n\n expect(buttons).toBeInstanceOf(DefaultButtonController);\n expect(touch).toBeInstanceOf(DefaultTouchController);\n expect(typeof buttons.press).toBe(\"function\");\n });\n\n it(\"creates fresh instances per invocation\", () => {\n const a = createDefaultControllers(\"https://x\", { screens: SCREENS });\n const b = createDefaultControllers(\"https://x\", { screens: SCREENS });\n\n expect(a.buttons).not.toBe(b.buttons);\n expect(a.touch).not.toBe(b.touch);\n });\n\n it(\"button.press posts the correct payload\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { buttons } = createDefaultControllers(\"https://x\", {\n screens: SCREENS,\n });\n\n await buttons.press(\"left\");\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://x/button/left\",\n expect.objectContaining({\n method: \"POST\",\n body: JSON.stringify({ action: \"press-and-release\" }),\n }),\n );\n });\n\n it(\"touch.tapAndRelease maps percent to absolute coords\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { touch } = createDefaultControllers(\"https://x\", {\n screens: SCREENS,\n });\n\n // 50% of 128x64 \u2192 (64, 32)\n await touch.tapAndRelease(\"flex\", { x: 50 as any, y: 50 as any });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://x/finger\",\n expect.objectContaining({\n method: \"POST\",\n body: JSON.stringify({\n action: \"press-and-release\",\n x: 64,\n y: 32,\n }),\n }),\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "AACA,OAAS,aAAAA,EAAW,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAA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AAY,CACpE,MAAMM,EAAWL,EACd,MAAM,WAAY,OAAO,EACzB,kBAAkB,IAAI,SAAS,IAAI,CAAC,EAEjC,CAAE,MAAAO,CAAM,EAAIJ,EAAyB,YAAa,CACtD,QAASC,CACX,CAAC,EAGD,MAAMG,EAAM,cAAc,OAAQ,CAAE,EAAG,GAAW,EAAG,EAAU,CAAC,EAEhET,EAAOO,CAAQ,EAAE,qBACf,mBACAP,EAAO,iBAAiB,CACtB,OAAQ,OACR,KAAM,KAAK,UAAU,CACnB,OAAQ,oBACR,EAAG,GACH,EAAG,EACL,CAAC,CACH,CAAC,CACH,CACF,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["afterEach", "describe", "expect", "it", "vi", "DefaultButtonController", "DefaultTouchController", "createDefaultControllers", "SCREENS", "fetchSpy", "buttons", "touch", "a", "b"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
1
|
+
const s=5e3,x=(t,n)=>async(e,a=s)=>{await t.tap(n,e),await new Promise(c=>setTimeout(c,a)),await t.release(n,e)},o=(t,n)=>async e=>await t.tapAndRelease(n,e),d=(t,n)=>async(e=s)=>await x(t,n)({x:85,y:80},e),C=(t,n)=>async()=>await o(t,n)({x:20,y:90}),p=(t,n)=>async()=>await o(t,n)({x:90,y:90}),O=(t,n)=>async()=>await o(t,n)({x:45,y:90}),u=(t,n)=>async()=>await o(t,n)({x:50,y:80}),T=(t,n)=>async()=>await o(t,n)({x:50,y:90}),S=(t,n)=>async()=>await o(t,n)({x:85,y:8}),_=(t,n)=>async()=>await o(t,n)({x:10,y:4}),r={stax:{x:88,y:51},flex:{x:88,y:58},apex:{x:88,y:58}},K=t=>Object.hasOwn(r,t),y={x:88,y:51},w=(t,n)=>async()=>{const e=K(n)?r[n]:y;await o(t,n)(e)},i={stax:{x:50,y:77},flex:{x:50,y:72}},l=t=>Object.hasOwn(i,t),g={x:50,y:72},h=(t,n)=>async()=>{const e=l(n)?i[n]:g;await o(t,n)(e)},B=(t,n)=>async()=>await o(t,n)({x:50,y:94}),D=(t,n)=>async()=>await o(t,n)({x:50,y:94});export{D as acceptBlindSigning,h as confirmAddressBookReview,B as continueToBlindSigning,w as enableBlindSigningSettings,S as enterMenu,_ as exitMenu,u as mainButton,p as navigateNext,O as navigatePrevious,C as reject,T as secondaryButton,d as sign,x as tapLong,o as tapQuick};
|
|
2
2
|
//# sourceMappingURL=touchUseCases.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/use-cases/touchUseCases.ts"],
|
|
4
|
-
"sourcesContent": ["import type { PercentCoordinates } from \"@internal/core/types\";\nimport { type TouchController } from \"@root/src/internal/core/TouchController\";\n\nconst TAP_LONG_TIME_MS = 5000;\n\nexport const tapLong =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates, delayMs: number = TAP_LONG_TIME_MS) => {\n await touch.tap(deviceKey, point);\n await new Promise((r) => setTimeout(r, delayMs));\n await touch.release(deviceKey, point);\n };\n\nexport const tapQuick =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates) =>\n await touch.tapAndRelease(deviceKey, point);\n\nexport const sign =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (delayMs: number = TAP_LONG_TIME_MS) =>\n await tapLong(touch, deviceKey)({ x: 85, y: 80 }, delayMs);\n\nexport const reject =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 20, y: 90 });\n\nexport const navigateNext =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 90, y: 90 });\n\nexport const navigatePrevious =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 45, y: 90 });\n\nexport const mainButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 80 });\n\nexport const secondaryButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 90 });\n"],
|
|
5
|
-
"mappings": "AAGA,MAAMA,EAAmB,IAEZC,EACX,CAAmBC,EAA2BC,IAC9C,MAAOC,EAA2BC,EAAkBL,IAAqB,CACvE,MAAME,EAAM,IAAIC,EAAWC,CAAK,EAChC,MAAM,IAAI,QAASE,GAAM,WAAWA,EAAGD,CAAO,CAAC,EAC/C,MAAMH,EAAM,QAAQC,EAAWC,CAAK,CACtC,EAEWG,EACX,CAAmBL,EAA2BC,IAC9C,MAAOC,GACL,MAAMF,EAAM,cAAcC,EAAWC,CAAK,EAEjCI,EACX,CAAmBN,EAA2BC,IAC9C,MAAOE,EAAkBL,IACvB,MAAMC,EAAQC,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,EAAGE,CAAO,EAEhDI,EACX,CAAmBP,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCO,EACX,CAAmBR,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCQ,EACX,CAAmBT,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCS,EACX,CAAmBV,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCU,EACX,CAAmBX,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC",
|
|
6
|
-
"names": ["TAP_LONG_TIME_MS", "tapLong", "touch", "deviceKey", "point", "delayMs", "r", "tapQuick", "sign", "reject", "navigateNext", "navigatePrevious", "mainButton", "secondaryButton"]
|
|
4
|
+
"sourcesContent": ["import type { PercentCoordinates } from \"@internal/core/types\";\nimport { type TouchController } from \"@root/src/internal/core/TouchController\";\n\nconst TAP_LONG_TIME_MS = 5000;\n\nexport const tapLong =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates, delayMs: number = TAP_LONG_TIME_MS) => {\n await touch.tap(deviceKey, point);\n await new Promise((r) => setTimeout(r, delayMs));\n await touch.release(deviceKey, point);\n };\n\nexport const tapQuick =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates) =>\n await touch.tapAndRelease(deviceKey, point);\n\nexport const sign =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (delayMs: number = TAP_LONG_TIME_MS) =>\n await tapLong(touch, deviceKey)({ x: 85, y: 80 }, delayMs);\n\nexport const reject =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 20, y: 90 });\n\nexport const navigateNext =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 90, y: 90 });\n\nexport const navigatePrevious =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 45, y: 90 });\n\nexport const mainButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 80 });\n\nexport const secondaryButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 90 });\n\nexport const enterMenu =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 85, y: 8 });\n\nexport const exitMenu =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 10, y: 4 });\n\nconst BLIND_SIGNING_TOGGLE_COORDS = {\n stax: { x: 88, y: 51 },\n flex: { x: 88, y: 58 },\n apex: { x: 88, y: 58 },\n} as const satisfies Record<string, PercentCoordinates>;\n\ntype BlindSigningTouchKey = keyof typeof BLIND_SIGNING_TOGGLE_COORDS;\n\nconst isBlindSigningTouchKey = (key: string): key is BlindSigningTouchKey =>\n Object.hasOwn(BLIND_SIGNING_TOGGLE_COORDS, key);\n\nconst DEFAULT_BLIND_SIGNING_TOGGLE_COORDS: PercentCoordinates = {\n x: 88,\n y: 51,\n};\n\nexport const enableBlindSigningSettings =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () => {\n const point = isBlindSigningTouchKey(deviceKey)\n ? BLIND_SIGNING_TOGGLE_COORDS[deviceKey]\n : DEFAULT_BLIND_SIGNING_TOGGLE_COORDS;\n await tapQuick(touch, deviceKey)(point);\n };\n\n/**\n * Confirm button of the Address Book review (REGISTER IDENTITY). NBGL's\n * \"review light\" puts this button above the page footer rather than in it, so\n * neither mainButton() nor secondaryButton() reaches it. Measured on Speculos:\n * flex 480x600 -> button centre y=436 (72%), stax 400x672 -> y=520 (77%).\n */\nconst ADDRESS_BOOK_CONFIRM_COORDS = {\n stax: { x: 50, y: 77 },\n flex: { x: 50, y: 72 },\n} as const satisfies Record<string, PercentCoordinates>;\n\ntype AddressBookConfirmKey = keyof typeof ADDRESS_BOOK_CONFIRM_COORDS;\n\nconst isAddressBookConfirmKey = (key: string): key is AddressBookConfirmKey =>\n Object.hasOwn(ADDRESS_BOOK_CONFIRM_COORDS, key);\n\n/** Flex's placement, used for any touchscreen model not measured above. */\nconst DEFAULT_ADDRESS_BOOK_CONFIRM_COORDS: PercentCoordinates = {\n x: 50,\n y: 72,\n};\n\nexport const confirmAddressBookReview =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () => {\n const point = isAddressBookConfirmKey(deviceKey)\n ? ADDRESS_BOOK_CONFIRM_COORDS[deviceKey]\n : DEFAULT_ADDRESS_BOOK_CONFIRM_COORDS;\n await tapQuick(touch, deviceKey)(point);\n };\n\nexport const continueToBlindSigning =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 94 });\n\nexport const acceptBlindSigning =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 94 });\n"],
|
|
5
|
+
"mappings": "AAGA,MAAMA,EAAmB,IAEZC,EACX,CAAmBC,EAA2BC,IAC9C,MAAOC,EAA2BC,EAAkBL,IAAqB,CACvE,MAAME,EAAM,IAAIC,EAAWC,CAAK,EAChC,MAAM,IAAI,QAASE,GAAM,WAAWA,EAAGD,CAAO,CAAC,EAC/C,MAAMH,EAAM,QAAQC,EAAWC,CAAK,CACtC,EAEWG,EACX,CAAmBL,EAA2BC,IAC9C,MAAOC,GACL,MAAMF,EAAM,cAAcC,EAAWC,CAAK,EAEjCI,EACX,CAAmBN,EAA2BC,IAC9C,MAAOE,EAAkBL,IACvB,MAAMC,EAAQC,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,EAAGE,CAAO,EAEhDI,EACX,CAAmBP,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCO,EACX,CAAmBR,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCQ,EACX,CAAmBT,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCS,EACX,CAAmBV,EAA2BC,IAC9C,SACE,MAAMI,EAASL,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCU,EACX,CAAmBX,EAA2BC,IAC9C,SACE,M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,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC",
|
|
6
|
+
"names": ["TAP_LONG_TIME_MS", "tapLong", "touch", "deviceKey", "point", "delayMs", "r", "tapQuick", "sign", "reject", "navigateNext", "navigatePrevious", "mainButton", "secondaryButton", "enterMenu", "exitMenu", "BLIND_SIGNING_TOGGLE_COORDS", "isBlindSigningTouchKey", "key", "DEFAULT_BLIND_SIGNING_TOGGLE_COORDS", "enableBlindSigningSettings", "ADDRESS_BOOK_CONFIRM_COORDS", "isAddressBookConfirmKey", "DEFAULT_ADDRESS_BOOK_CONFIRM_COORDS", "confirmAddressBookReview", "continueToBlindSigning", "acceptBlindSigning"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{tapLong as
|
|
1
|
+
import{acceptBlindSigning as p,confirmAddressBookReview as c,continueToBlindSigning as v,enableBlindSigningSettings as r,enterMenu as x,exitMenu as u,mainButton as m,navigateNext as y,navigatePrevious as T,reject as B,secondaryButton as h,sign as d,tapLong as i,tapQuick as g}from"./touchUseCases";describe("touchUsecases",()=>{const n="devA",o={x:50,y:30};let e;beforeEach(()=>{e={tap:vi.fn().mockResolvedValue(void 0),release:vi.fn().mockResolvedValue(void 0),tapAndRelease:vi.fn().mockResolvedValue(void 0)},vi.restoreAllMocks(),vi.useRealTimers()}),it("tapQuick calls tapAndRelease with the same deviceKey and point",async()=>{await g(e,n)(o),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(n,o),expect(e.tap).not.toHaveBeenCalled(),expect(e.release).not.toHaveBeenCalled()}),it("tapLong taps, waits default timeout, then releases",async()=>{vi.useFakeTimers();const t=vi.spyOn(globalThis,"setTimeout"),s=i(e,n)(o);await Promise.resolve(),expect(e.tap).toHaveBeenCalledTimes(1),expect(e.tap).toHaveBeenCalledWith(n,o),expect(t).toHaveBeenCalledTimes(1),expect(t).toHaveBeenLastCalledWith(expect.any(Function),5e3),expect(e.release).not.toHaveBeenCalled(),await vi.advanceTimersByTimeAsync(5e3),await s,expect(e.release).toHaveBeenCalledTimes(1),expect(e.release).toHaveBeenCalledWith(n,o)}),it("tapLong uses the provided delayMs value",async()=>{vi.useFakeTimers();const t=vi.spyOn(globalThis,"setTimeout"),a=1234,l=i(e,n)(o,a);await Promise.resolve(),expect(e.tap).toHaveBeenCalledTimes(1),expect(e.tap).toHaveBeenCalledWith(n,o),expect(t).toHaveBeenCalledTimes(1),expect(t).toHaveBeenLastCalledWith(expect.any(Function),a),expect(e.release).not.toHaveBeenCalled(),await vi.advanceTimersByTimeAsync(a),await l,expect(e.release).toHaveBeenCalledTimes(1),expect(e.release).toHaveBeenCalledWith(n,o)}),it("tapLong propagates error if tap() rejects (no release)",async()=>{vi.useFakeTimers();const t=new Error("tap failed");e.tap.mockRejectedValueOnce(t);const s=i(e,n)(o);await expect(s).rejects.toThrow("tap failed"),expect(e.release).not.toHaveBeenCalled()}),it("tapLong propagates error if release() rejects",async()=>{vi.useFakeTimers();const t=new Error("release failed");e.release.mockRejectedValueOnce(t);const a=i(e,n)(o),s=expect(a).rejects.toThrow("release failed");await Promise.resolve(),await vi.advanceTimersByTimeAsync(5e3),await s,expect(e.tap).toHaveBeenCalledTimes(1),expect(e.release).toHaveBeenCalledTimes(1)}),describe("enableBlindSigningSettings",()=>{it.each([["stax",{x:88,y:51}],["flex",{x:88,y:58}],["apex",{x:88,y:58}]])("taps the blind-signing toggle at the %s coordinates",async(t,a)=>{await r(e,t)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(t,a)}),it("falls back to default coordinates for an unknown device key",async()=>{const t="unknown";await r(e,t)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(t,{x:88,y:51})})}),describe("fixed-coordinate taps",()=>{it.each([["reject",B,{x:20,y:90}],["navigateNext",y,{x:90,y:90}],["navigatePrevious",T,{x:45,y:90}],["mainButton",m,{x:50,y:80}],["secondaryButton",h,{x:50,y:90}],["enterMenu",x,{x:85,y:8}],["exitMenu",u,{x:10,y:4}],["continueToBlindSigning",v,{x:50,y:94}],["acceptBlindSigning",p,{x:50,y:94}]])("%s taps %o",async(t,a,s)=>{await a(e,n)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(n,s)})}),describe("sign",()=>{const t={x:85,y:80};it("holds the sign button for the default 5s",async()=>{vi.useFakeTimers();const a=vi.spyOn(globalThis,"setTimeout"),s=d(e,n)();await Promise.resolve(),expect(e.tap).toHaveBeenCalledWith(n,t),expect(a).toHaveBeenLastCalledWith(expect.any(Function),5e3),await vi.advanceTimersByTimeAsync(5e3),await s,expect(e.release).toHaveBeenCalledWith(n,t)}),it("holds the sign button for the provided delay",async()=>{vi.useFakeTimers();const a=vi.spyOn(globalThis,"setTimeout"),s=250,l=d(e,n)(s);await Promise.resolve(),expect(a).toHaveBeenLastCalledWith(expect.any(Function),s),await vi.advanceTimersByTimeAsync(s),await l,expect(e.release).toHaveBeenCalledTimes(1)})}),describe("confirmAddressBookReview",()=>{it.each([["stax",{x:50,y:77}],["flex",{x:50,y:72}]])("taps the Confirm button at the %s coordinates",async(t,a)=>{await c(e,t)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(t,a)}),it("falls back to Flex coordinates for an unmeasured device key",async()=>{const t="apex";await c(e,t)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(t,{x:50,y:72})})})});
|
|
2
2
|
//# sourceMappingURL=touchUseCases.test.js.map
|