@ledgerhq/device-mockserver-react-core 0.0.0-stage → 0.1.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/LICENSE.MD +202 -0
- package/README.md +28 -2
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +7 -0
- package/lib/cjs/package.json +61 -0
- package/lib/cjs/src/deviceModels.js +2 -0
- package/lib/cjs/src/deviceModels.js.map +7 -0
- package/lib/cjs/src/deviceModels.test.js +2 -0
- package/lib/cjs/src/deviceModels.test.js.map +7 -0
- package/lib/cjs/src/index.js +2 -0
- package/lib/cjs/src/index.js.map +7 -0
- package/lib/cjs/src/mockServerScreenApi.js +2 -0
- package/lib/cjs/src/mockServerScreenApi.js.map +7 -0
- package/lib/cjs/src/mockServerScreenApi.test.js +2 -0
- package/lib/cjs/src/mockServerScreenApi.test.js.map +7 -0
- package/lib/cjs/src/types.js +2 -0
- package/lib/cjs/src/types.js.map +7 -0
- package/lib/cjs/src/useButtonHold.js +2 -0
- package/lib/cjs/src/useButtonHold.js.map +7 -0
- package/lib/cjs/src/useButtonHold.test.js +2 -0
- package/lib/cjs/src/useButtonHold.test.js.map +7 -0
- package/lib/cjs/src/useHold.js +2 -0
- package/lib/cjs/src/useHold.js.map +7 -0
- package/lib/cjs/src/useMockServerDevice.js +2 -0
- package/lib/cjs/src/useMockServerDevice.js.map +7 -0
- package/lib/cjs/src/useMockServerDevice.test.js +2 -0
- package/lib/cjs/src/useMockServerDevice.test.js.map +7 -0
- package/lib/cjs/src/useOpenApp.js +2 -0
- package/lib/cjs/src/useOpenApp.js.map +7 -0
- package/lib/cjs/src/useOpenApp.test.js +2 -0
- package/lib/cjs/src/useOpenApp.test.js.map +7 -0
- package/lib/cjs/src/useScreenPolling.js +2 -0
- package/lib/cjs/src/useScreenPolling.js.map +7 -0
- package/lib/cjs/src/useScreenPolling.test.js +2 -0
- package/lib/cjs/src/useScreenPolling.test.js.map +7 -0
- package/lib/cjs/src/useTouchHold.js +2 -0
- package/lib/cjs/src/useTouchHold.js.map +7 -0
- package/lib/cjs/src/useTouchHold.test.js +2 -0
- package/lib/cjs/src/useTouchHold.test.js.map +7 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +7 -0
- package/lib/esm/package.json +61 -0
- package/lib/esm/src/deviceModels.js +2 -0
- package/lib/esm/src/deviceModels.js.map +7 -0
- package/lib/esm/src/deviceModels.test.js +2 -0
- package/lib/esm/src/deviceModels.test.js.map +7 -0
- package/lib/esm/src/index.js +2 -0
- package/lib/esm/src/index.js.map +7 -0
- package/lib/esm/src/mockServerScreenApi.js +2 -0
- package/lib/esm/src/mockServerScreenApi.js.map +7 -0
- package/lib/esm/src/mockServerScreenApi.test.js +2 -0
- package/lib/esm/src/mockServerScreenApi.test.js.map +7 -0
- package/lib/esm/src/types.js +1 -0
- package/lib/esm/src/types.js.map +7 -0
- package/lib/esm/src/useButtonHold.js +2 -0
- package/lib/esm/src/useButtonHold.js.map +7 -0
- package/lib/esm/src/useButtonHold.test.js +2 -0
- package/lib/esm/src/useButtonHold.test.js.map +7 -0
- package/lib/esm/src/useHold.js +2 -0
- package/lib/esm/src/useHold.js.map +7 -0
- package/lib/esm/src/useMockServerDevice.js +2 -0
- package/lib/esm/src/useMockServerDevice.js.map +7 -0
- package/lib/esm/src/useMockServerDevice.test.js +2 -0
- package/lib/esm/src/useMockServerDevice.test.js.map +7 -0
- package/lib/esm/src/useOpenApp.js +2 -0
- package/lib/esm/src/useOpenApp.js.map +7 -0
- package/lib/esm/src/useOpenApp.test.js +2 -0
- package/lib/esm/src/useOpenApp.test.js.map +7 -0
- package/lib/esm/src/useScreenPolling.js +2 -0
- package/lib/esm/src/useScreenPolling.js.map +7 -0
- package/lib/esm/src/useScreenPolling.test.js +2 -0
- package/lib/esm/src/useScreenPolling.test.js.map +7 -0
- package/lib/esm/src/useTouchHold.js +2 -0
- package/lib/esm/src/useTouchHold.js.map +7 -0
- package/lib/esm/src/useTouchHold.test.js +2 -0
- package/lib/esm/src/useTouchHold.test.js.map +7 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/src/deviceModels.d.ts +12 -0
- package/lib/types/src/deviceModels.d.ts.map +1 -0
- package/lib/types/src/deviceModels.test.d.ts +2 -0
- package/lib/types/src/deviceModels.test.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +10 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/mockServerScreenApi.d.ts +3 -0
- package/lib/types/src/mockServerScreenApi.d.ts.map +1 -0
- package/lib/types/src/mockServerScreenApi.test.d.ts +2 -0
- package/lib/types/src/mockServerScreenApi.test.d.ts.map +1 -0
- package/lib/types/src/types.d.ts +60 -0
- package/lib/types/src/types.d.ts.map +1 -0
- package/lib/types/src/useButtonHold.d.ts +6 -0
- package/lib/types/src/useButtonHold.d.ts.map +1 -0
- package/lib/types/src/useButtonHold.test.d.ts +2 -0
- package/lib/types/src/useButtonHold.test.d.ts.map +1 -0
- package/lib/types/src/useHold.d.ts +23 -0
- package/lib/types/src/useHold.d.ts.map +1 -0
- package/lib/types/src/useMockServerDevice.d.ts +9 -0
- package/lib/types/src/useMockServerDevice.d.ts.map +1 -0
- package/lib/types/src/useMockServerDevice.test.d.ts +2 -0
- package/lib/types/src/useMockServerDevice.test.d.ts.map +1 -0
- package/lib/types/src/useOpenApp.d.ts +19 -0
- package/lib/types/src/useOpenApp.d.ts.map +1 -0
- package/lib/types/src/useOpenApp.test.d.ts +2 -0
- package/lib/types/src/useOpenApp.test.d.ts.map +1 -0
- package/lib/types/src/useScreenPolling.d.ts +3 -0
- package/lib/types/src/useScreenPolling.d.ts.map +1 -0
- package/lib/types/src/useScreenPolling.test.d.ts +2 -0
- package/lib/types/src/useScreenPolling.test.d.ts.map +1 -0
- package/lib/types/src/useTouchHold.d.ts +23 -0
- package/lib/types/src/useTouchHold.d.ts.map +1 -0
- package/lib/types/src/useTouchHold.test.d.ts +2 -0
- package/lib/types/src/useTouchHold.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -0
- package/package.json +58 -3
package/LICENSE.MD
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2024-present Ledger
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ledgerhq/device-mockserver-react-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The platform-free part of the [device mock server](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/apps/device-mock-server)
|
|
4
|
+
screens: React hooks and helpers with no DOM, React Native or design system
|
|
5
|
+
import. Two packages draw it:
|
|
6
|
+
|
|
7
|
+
- [`@ledgerhq/device-mockserver-react`](../mockserver-device-react) for the web.
|
|
8
|
+
- [`@ledgerhq/device-mockserver-react-native`](../mockserver-device-react-native)
|
|
9
|
+
for React Native.
|
|
10
|
+
|
|
11
|
+
Use one of those to show a device screen. Use this package directly only to
|
|
12
|
+
build a screen for another platform.
|
|
13
|
+
|
|
14
|
+
## Contents
|
|
15
|
+
|
|
16
|
+
| Export | Role |
|
|
17
|
+
| ----------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
18
|
+
| `useScreenPolling(api, polling, platform)` | Polls the screen: a live frame, the device record while no app runs, or an error. |
|
|
19
|
+
| `ScreenPlatform` | What the platform supplies: how a frame becomes an image source, and when the app is hidden. |
|
|
20
|
+
| `mockServerScreenApi(client, deviceId)` | A `ScreenApi` that reaches a device through the mock server. |
|
|
21
|
+
| `useMockServerDevice(client, deviceId)` | The mock server's record of a device. |
|
|
22
|
+
| `findDeviceScreenModel(deviceType)` | Touch or buttons, screen size and colour of a device model. |
|
|
23
|
+
| `useHold(onAction)` | Sends a quick click or tap as one press-and-release, and a longer hold as a press, then a release. |
|
|
24
|
+
| `useButtonHold(onPress)`, `useTouchHold(onTouch)` | `useHold` for the Nano buttons, and for touches in device pixels. |
|
|
25
|
+
| `toScreenPoint` | Maps a point on the drawn screen to device pixels. |
|
|
26
|
+
| `useOpenApp(onOpenApp)`, `openableApps`, `appIconUrl` | Opens an app from the device's list and waits for its screen. |
|
|
27
|
+
|
|
28
|
+
Pass `useScreenPolling` a `ScreenPlatform` defined at module level. Polling
|
|
29
|
+
restarts whenever the object changes.
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("./src"),module.exports);0&&(module.exports={...require("./src")});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@ledgerhq/device-mockserver-client": "^1.4.0"
|
|
4
|
+
},
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@ledgerhq/device-management-kit": "workspace:^",
|
|
7
|
+
"@ledgerhq/eslint-config-dsdk": "workspace:^",
|
|
8
|
+
"@ledgerhq/ldmk-tool": "workspace:^",
|
|
9
|
+
"@ledgerhq/prettier-config-dsdk": "workspace:^",
|
|
10
|
+
"@ledgerhq/tsconfig-dsdk": "workspace:^",
|
|
11
|
+
"@ledgerhq/vitest-config-dmk": "workspace:^",
|
|
12
|
+
"@types/react": "catalog:",
|
|
13
|
+
"@types/react-dom": "catalog:",
|
|
14
|
+
"react": "catalog:",
|
|
15
|
+
"react-dom": "catalog:"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./lib/esm/index.js",
|
|
20
|
+
"require": "./lib/cjs/index.js",
|
|
21
|
+
"types": "./lib/types/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./*": {
|
|
24
|
+
"import": "./lib/esm/*",
|
|
25
|
+
"require": "./lib/cjs/*",
|
|
26
|
+
"types": "./lib/types/*"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"./lib"
|
|
31
|
+
],
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"main": "lib/cjs/index.js",
|
|
34
|
+
"name": "@ledgerhq/device-mockserver-react-core",
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@ledgerhq/device-management-kit": "^1.11.0",
|
|
37
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"private": false,
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/LedgerHQ/device-sdk-ts.git"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "pnpm ldmk-tool build --entryPoints index.ts,src/*.tsx,src/*.ts --tsconfig tsconfig.prod.json",
|
|
46
|
+
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
|
|
47
|
+
"lint": "eslint",
|
|
48
|
+
"lint:fix": "pnpm lint --fix",
|
|
49
|
+
"prebuild": "rimraf lib",
|
|
50
|
+
"prettier": "prettier . --check",
|
|
51
|
+
"prettier:fix": "prettier . --write",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:coverage": "vitest run --coverage",
|
|
54
|
+
"test:watch": "vitest",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/*.tsx,src/*.ts --tsconfig tsconfig.prod.json",
|
|
57
|
+
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
58
|
+
},
|
|
59
|
+
"types": "lib/types/index.d.ts",
|
|
60
|
+
"version": "0.1.0"
|
|
61
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var t=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var u=(e,n)=>{for(var c in n)t(e,c,{get:n[c],enumerable:!0})},d=(e,n,c,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!i.call(e,r)&&r!==c&&t(e,r,{get:()=>n[r],enumerable:!(l=s(n,r))||l.enumerable});return e};var h=e=>d(t({},"__esModule",{value:!0}),e);var b={};u(b,{findDeviceScreenModel:()=>p});module.exports=h(b);const o=(e,n)=>({label:e,touch:!1,speculos:!0,screenWidth:128,screenHeight:n,lightScreen:!1}),S={nanoS:{...o("Nano S",32),speculos:!1},nanoSP:o("Nano S Plus",64),nanoX:o("Nano X",64),stax:{label:"Stax",touch:!0,speculos:!0,screenWidth:400,screenHeight:672,lightScreen:!0},flex:{label:"Flex",touch:!0,speculos:!0,screenWidth:480,screenHeight:600,lightScreen:!0},apexp:{label:"Apex",touch:!0,speculos:!0,screenWidth:300,screenHeight:400,lightScreen:!0}},g=o("Device",64),p=e=>S[e]??g;0&&(module.exports={findDeviceScreenModel});
|
|
2
|
+
//# sourceMappingURL=deviceModels.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/deviceModels.ts"],
|
|
4
|
+
"sourcesContent": ["export interface DeviceScreenModel {\n readonly label: string;\n readonly touch: boolean;\n /** Whether Speculos has an emulator for it, so it can have a screen. */\n readonly speculos: boolean;\n /** In device pixels. */\n readonly screenWidth: number;\n readonly screenHeight: number;\n readonly lightScreen: boolean;\n}\n\nconst nano = (label: string, screenHeight: number): DeviceScreenModel => ({\n label,\n touch: false,\n speculos: true,\n screenWidth: 128,\n screenHeight,\n lightScreen: false,\n});\n\n/** Keyed by the mock server's `device_type`, a DMK `DeviceModelId`. */\nconst MODELS: Record<string, DeviceScreenModel> = {\n nanoS: { ...nano(\"Nano S\", 32), speculos: false },\n nanoSP: nano(\"Nano S Plus\", 64),\n nanoX: nano(\"Nano X\", 64),\n stax: {\n label: \"Stax\",\n touch: true,\n speculos: true,\n screenWidth: 400,\n screenHeight: 672,\n lightScreen: true,\n },\n flex: {\n label: \"Flex\",\n touch: true,\n speculos: true,\n screenWidth: 480,\n screenHeight: 600,\n lightScreen: true,\n },\n apexp: {\n label: \"Apex\",\n touch: true,\n speculos: true,\n screenWidth: 300,\n screenHeight: 400,\n lightScreen: true,\n },\n};\n\nconst UNKNOWN: DeviceScreenModel = nano(\"Device\", 64);\n\nexport const findDeviceScreenModel = (deviceType: string): DeviceScreenModel =>\n MODELS[deviceType] ?? UNKNOWN;\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAWA,MAAMI,EAAO,CAACC,EAAeC,KAA6C,CACxE,MAAAD,EACA,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAAC,EACA,YAAa,EACf,GAGMC,EAA4C,CAChD,MAAO,CAAE,GAAGH,EAAK,SAAU,EAAE,EAAG,SAAU,EAAM,EAChD,OAAQA,EAAK,cAAe,EAAE,EAC9B,MAAOA,EAAK,SAAU,EAAE,EACxB,KAAM,CACJ,MAAO,OACP,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,EACA,KAAM,CACJ,MAAO,OACP,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,EACA,MAAO,CACL,MAAO,OACP,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,CACF,EAEMI,EAA6BJ,EAAK,SAAU,EAAE,EAEvCF,EAAyBO,GACpCF,EAAOE,CAAU,GAAKD",
|
|
6
|
+
"names": ["deviceModels_exports", "__export", "findDeviceScreenModel", "__toCommonJS", "nano", "label", "screenHeight", "MODELS", "UNKNOWN", "deviceType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("./deviceModels");describe("findDeviceScreenModel",()=>{it("finds a model by the mock server's device type",()=>{expect((0,e.findDeviceScreenModel)("stax")).toMatchObject({label:"Stax",touch:!0,speculos:!0})}),it("marks Nano S as having no emulator",()=>{expect((0,e.findDeviceScreenModel)("nanoS").speculos).toBe(!1)}),it("falls back to a button-driven model for an unknown type",()=>{expect((0,e.findDeviceScreenModel)("unknown")).toMatchObject({label:"Device",touch:!1})})});
|
|
2
|
+
//# sourceMappingURL=deviceModels.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/deviceModels.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { findDeviceScreenModel } from \"./deviceModels\";\n\ndescribe(\"findDeviceScreenModel\", () => {\n it(\"finds a model by the mock server's device type\", () => {\n expect(findDeviceScreenModel(\"stax\")).toMatchObject({\n label: \"Stax\",\n touch: true,\n speculos: true,\n });\n });\n\n it(\"marks Nano S as having no emulator\", () => {\n expect(findDeviceScreenModel(\"nanoS\").speculos).toBe(false);\n });\n\n it(\"falls back to a button-driven model for an unknown type\", () => {\n expect(findDeviceScreenModel(\"unknown\")).toMatchObject({\n label: \"Device\",\n touch: false,\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAsC,0BAEtC,SAAS,wBAAyB,IAAM,CACtC,GAAG,iDAAkD,IAAM,CACzD,UAAO,yBAAsB,MAAM,CAAC,EAAE,cAAc,CAClD,MAAO,OACP,MAAO,GACP,SAAU,EACZ,CAAC,CACH,CAAC,EAED,GAAG,qCAAsC,IAAM,CAC7C,UAAO,yBAAsB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAK,CAC5D,CAAC,EAED,GAAG,0DAA2D,IAAM,CAClE,UAAO,yBAAsB,SAAS,CAAC,EAAE,cAAc,CACrD,MAAO,SACP,MAAO,EACT,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_deviceModels"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var S=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var s=(r,e)=>{for(var t in e)S(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of y(e))!H.call(r,p)&&p!==t&&S(r,p,{get:()=>e[p],enumerable:!(l=x(e,p))||l.enumerable});return r};var D=r=>v(S({},"__esModule",{value:!0}),r);var M={};s(M,{HOLD_THRESHOLD_MS:()=>n.HOLD_THRESHOLD_MS,OPEN_APP_TIMEOUT_MS:()=>o.OPEN_APP_TIMEOUT_MS,appIconUrl:()=>o.appIconUrl,findDeviceScreenModel:()=>i.findDeviceScreenModel,mockServerScreenApi:()=>f.mockServerScreenApi,openableApps:()=>o.openableApps,toScreenPoint:()=>c.toScreenPoint,useButtonHold:()=>m.useButtonHold,useHold:()=>n.useHold,useMockServerDevice:()=>u.useMockServerDevice,useOpenApp:()=>o.useOpenApp,useScreenPolling:()=>d.useScreenPolling,useTouchHold:()=>c.useTouchHold});module.exports=D(M);var i=require("./deviceModels"),f=require("./mockServerScreenApi"),m=require("./useButtonHold"),n=require("./useHold"),u=require("./useMockServerDevice"),o=require("./useOpenApp"),d=require("./useScreenPolling"),c=require("./useTouchHold");0&&(module.exports={HOLD_THRESHOLD_MS,OPEN_APP_TIMEOUT_MS,appIconUrl,findDeviceScreenModel,mockServerScreenApi,openableApps,toScreenPoint,useButtonHold,useHold,useMockServerDevice,useOpenApp,useScreenPolling,useTouchHold});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { type DeviceScreenModel, findDeviceScreenModel } from \"./deviceModels\";\nexport { mockServerScreenApi } from \"./mockServerScreenApi\";\nexport type {\n DeviceScreenInput,\n DeviceScreenState,\n MockServerClient,\n ScreenApi,\n ScreenPlatform,\n} from \"./types\";\nexport { type ButtonHold, useButtonHold } from \"./useButtonHold\";\nexport { type Hold, HOLD_THRESHOLD_MS, useHold } from \"./useHold\";\nexport { useMockServerDevice } from \"./useMockServerDevice\";\nexport {\n appIconUrl,\n OPEN_APP_TIMEOUT_MS,\n openableApps,\n type OpenApp,\n useOpenApp,\n} from \"./useOpenApp\";\nexport { useScreenPolling } from \"./useScreenPolling\";\nexport {\n type ScreenPoint,\n type Size,\n toScreenPoint,\n type TouchHold,\n useTouchHold,\n} from \"./useTouchHold\";\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kfAAAE,EAAAF,GAAA,IAAAG,EAA8D,0BAC9DC,EAAoC,iCAQpCC,EAA+C,2BAC/CC,EAAsD,qBACtDC,EAAoC,iCACpCC,EAMO,wBACPC,EAAiC,8BACjCC,EAMO",
|
|
6
|
+
"names": ["src_exports", "__export", "__toCommonJS", "import_deviceModels", "import_mockServerScreenApi", "import_useButtonHold", "import_useHold", "import_useMockServerDevice", "import_useOpenApp", "import_useScreenPolling", "import_useTouchHold"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var i=(n,o)=>{for(var e in o)s(n,e,{get:o[e],enumerable:!0})},w=(n,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of u(o))!p.call(n,r)&&r!==e&&s(n,r,{get:()=>o[r],enumerable:!(t=a(o,r))||t.enumerable});return n};var h=n=>w(s({},"__esModule",{value:!0}),n);var S={};i(S,{mockServerScreenApi:()=>f});module.exports=h(S);const l=n=>n?.status===409,f=(n,o)=>({screenshot:async()=>{try{return await n.getScreenshot(o)}catch(e){if(l(e))return null;throw e}},idle:async()=>({kind:"os-info",device:await n.getDevice(o)}),pressButton:(e,t)=>n.pressButton(o,e,t),touch:(e,t,r)=>n.touchScreen(o,e,t,r),openApp:async e=>{const t=new TextEncoder().encode(e);if(t.length>255)throw new Error(`App name too long to open: ${e}`);const{response:r}=await n.sendApdu(o,Uint8Array.from([224,216,0,0,t.length,...t])),c=r.slice(-4);if(c!=="9000")throw new Error(`Could not open ${e} (${c})`)}});0&&(module.exports={mockServerScreenApi});
|
|
2
|
+
//# sourceMappingURL=mockServerScreenApi.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mockServerScreenApi.ts"],
|
|
4
|
+
"sourcesContent": ["import { type MockServerClient, type ScreenApi } from \"./types\";\n\n/** The proxy answers 409 when the device has no Speculos instance. */\nconst isNoInstance = (error: unknown): boolean =>\n (error as { status?: unknown } | null)?.status === 409;\n\nexport const mockServerScreenApi = (\n client: MockServerClient,\n deviceId: string,\n): ScreenApi => ({\n screenshot: async () => {\n try {\n return await client.getScreenshot(deviceId);\n } catch (error) {\n if (isNoInstance(error)) return null;\n throw error;\n }\n },\n idle: async () => ({\n kind: \"os-info\",\n device: await client.getDevice(deviceId),\n }),\n pressButton: (button, action) => client.pressButton(deviceId, button, action),\n touch: (x, y, action) => client.touchScreen(deviceId, x, y, action),\n openApp: async (appName) => {\n const name = new TextEncoder().encode(appName);\n // Lc is a single byte.\n if (name.length > 0xff) {\n throw new Error(`App name too long to open: ${appName}`);\n }\n const { response } = await client.sendApdu(\n deviceId,\n Uint8Array.from([0xe0, 0xd8, 0x00, 0x00, name.length, ...name]),\n );\n const statusWord = response.slice(-4);\n if (statusWord !== \"9000\") {\n throw new Error(`Could not open ${appName} (${statusWord})`);\n }\n },\n});\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAGA,MAAMI,EAAgBC,GACnBA,GAAuC,SAAW,IAExCH,EAAsB,CACjCI,EACAC,KACe,CACf,WAAY,SAAY,CACtB,GAAI,CACF,OAAO,MAAMD,EAAO,cAAcC,CAAQ,CAC5C,OAASF,EAAO,CACd,GAAID,EAAaC,CAAK,EAAG,OAAO,KAChC,MAAMA,CACR,CACF,EACA,KAAM,UAAa,CACjB,KAAM,UACN,OAAQ,MAAMC,EAAO,UAAUC,CAAQ,CACzC,GACA,YAAa,CAACC,EAAQC,IAAWH,EAAO,YAAYC,EAAUC,EAAQC,CAAM,EAC5E,MAAO,CAACC,EAAGC,EAAGF,IAAWH,EAAO,YAAYC,EAAUG,EAAGC,EAAGF,CAAM,EAClE,QAAS,MAAOG,GAAY,CAC1B,MAAMC,EAAO,IAAI,YAAY,EAAE,OAAOD,CAAO,EAE7C,GAAIC,EAAK,OAAS,IAChB,MAAM,IAAI,MAAM,8BAA8BD,CAAO,EAAE,EAEzD,KAAM,CAAE,SAAAE,CAAS,EAAI,MAAMR,EAAO,SAChCC,EACA,WAAW,KAAK,CAAC,IAAM,IAAM,EAAM,EAAMM,EAAK,OAAQ,GAAGA,CAAI,CAAC,CAChE,EACME,EAAaD,EAAS,MAAM,EAAE,EACpC,GAAIC,IAAe,OACjB,MAAM,IAAI,MAAM,kBAAkBH,CAAO,KAAKG,CAAU,GAAG,CAE/D,CACF",
|
|
6
|
+
"names": ["mockServerScreenApi_exports", "__export", "mockServerScreenApi", "__toCommonJS", "isNoInstance", "error", "client", "deviceId", "button", "action", "x", "y", "appName", "name", "response", "statusWord"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=require("./mockServerScreenApi");const n=e=>({getScreenshot:vi.fn(),getDevice:vi.fn(),pressButton:vi.fn(()=>Promise.resolve()),touchScreen:vi.fn(()=>Promise.resolve()),...e});describe("mockServerScreenApi",()=>{it("resolves the screenshot of the device",async()=>{const e=new Blob(["png"]),t=n({getScreenshot:vi.fn(()=>Promise.resolve(e))});await expect((0,o.mockServerScreenApi)(t,"device-1").screenshot()).resolves.toBe(e),expect(t.getScreenshot).toHaveBeenCalledWith("device-1")}),it("resolves no screenshot when the device has no Speculos instance",async()=>{const e=n({getScreenshot:vi.fn(()=>Promise.reject({status:409}))});await expect((0,o.mockServerScreenApi)(e,"device-1").screenshot()).resolves.toBeNull()}),it("rethrows any other screenshot failure",async()=>{const e=Object.assign(new Error("boom"),{status:500}),t=n({getScreenshot:vi.fn(()=>Promise.reject(e))});await expect((0,o.mockServerScreenApi)(t,"device-1").screenshot()).rejects.toBe(e)}),it("shows the device record while idle",async()=>{const e={id:"device-1",device_type:"nanoX"},t=n({getDevice:vi.fn(()=>Promise.resolve(e))});await expect((0,o.mockServerScreenApi)(t,"device-1").idle?.()).resolves.toEqual({kind:"os-info",device:e})}),it("forwards buttons and touches to the device",async()=>{const e=n({}),t=(0,o.mockServerScreenApi)(e,"device-1");await t.pressButton("left","press"),await t.touch(10,20,"release"),expect(e.pressButton).toHaveBeenCalledWith("device-1","left","press"),expect(e.touchScreen).toHaveBeenCalledWith("device-1",10,20,"release")}),it("opens an app by name",async()=>{const e=vi.fn(()=>Promise.resolve({response:"9000"}));await(0,o.mockServerScreenApi)(n({sendApdu:e}),"device-1").openApp?.("Bitcoin"),expect(e).toHaveBeenCalledWith("device-1",Uint8Array.from([224,216,0,0,7,...new TextEncoder().encode("Bitcoin")]))}),it("fails to open an app the device refuses",async()=>{const e=vi.fn(()=>Promise.resolve({response:"6807"})),t=(0,o.mockServerScreenApi)(n({sendApdu:e}),"device-1");await expect(t.openApp?.("Bitcoin")).rejects.toThrow("6807")}),it("refuses an app name too long for one APDU",async()=>{const e=vi.fn(()=>Promise.resolve({response:"9000"})),t=(0,o.mockServerScreenApi)(n({sendApdu:e}),"device-1");await expect(t.openApp?.("a".repeat(256))).rejects.toThrow("too long"),expect(e).not.toHaveBeenCalled()})});
|
|
2
|
+
//# sourceMappingURL=mockServerScreenApi.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mockServerScreenApi.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { mockServerScreenApi } from \"./mockServerScreenApi\";\nimport { type MockServerClient } from \"./types\";\n\nconst aClient = (overrides: Partial<Record<keyof MockServerClient, unknown>>) =>\n ({\n getScreenshot: vi.fn(),\n getDevice: vi.fn(),\n pressButton: vi.fn(() => Promise.resolve()),\n touchScreen: vi.fn(() => Promise.resolve()),\n ...overrides,\n }) as unknown as MockServerClient;\n\ndescribe(\"mockServerScreenApi\", () => {\n it(\"resolves the screenshot of the device\", async () => {\n const blob = new Blob([\"png\"]);\n const client = aClient({\n getScreenshot: vi.fn(() => Promise.resolve(blob)),\n });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").screenshot(),\n ).resolves.toBe(blob);\n expect(client.getScreenshot).toHaveBeenCalledWith(\"device-1\");\n });\n\n it(\"resolves no screenshot when the device has no Speculos instance\", async () => {\n const client = aClient({\n getScreenshot: vi.fn(() => Promise.reject({ status: 409 })),\n });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").screenshot(),\n ).resolves.toBeNull();\n });\n\n it(\"rethrows any other screenshot failure\", async () => {\n const error = Object.assign(new Error(\"boom\"), { status: 500 });\n const client = aClient({\n getScreenshot: vi.fn(() => Promise.reject(error)),\n });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").screenshot(),\n ).rejects.toBe(error);\n });\n\n it(\"shows the device record while idle\", async () => {\n const device = { id: \"device-1\", device_type: \"nanoX\" };\n const client = aClient({ getDevice: vi.fn(() => Promise.resolve(device)) });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").idle?.(),\n ).resolves.toEqual({\n kind: \"os-info\",\n device,\n });\n });\n\n it(\"forwards buttons and touches to the device\", async () => {\n const client = aClient({});\n const api = mockServerScreenApi(client, \"device-1\");\n\n await api.pressButton(\"left\", \"press\");\n await api.touch(10, 20, \"release\");\n\n expect(client.pressButton).toHaveBeenCalledWith(\n \"device-1\",\n \"left\",\n \"press\",\n );\n expect(client.touchScreen).toHaveBeenCalledWith(\n \"device-1\",\n 10,\n 20,\n \"release\",\n );\n });\n\n it(\"opens an app by name\", async () => {\n const sendApdu = vi.fn(() => Promise.resolve({ response: \"9000\" }));\n const api = mockServerScreenApi(aClient({ sendApdu }), \"device-1\");\n\n await api.openApp?.(\"Bitcoin\");\n\n expect(sendApdu).toHaveBeenCalledWith(\n \"device-1\",\n Uint8Array.from([\n 0xe0,\n 0xd8,\n 0x00,\n 0x00,\n 0x07,\n ...new TextEncoder().encode(\"Bitcoin\"),\n ]),\n );\n });\n\n it(\"fails to open an app the device refuses\", async () => {\n const sendApdu = vi.fn(() => Promise.resolve({ response: \"6807\" }));\n const api = mockServerScreenApi(aClient({ sendApdu }), \"device-1\");\n\n await expect(api.openApp?.(\"Bitcoin\")).rejects.toThrow(\"6807\");\n });\n\n it(\"refuses an app name too long for one APDU\", async () => {\n const sendApdu = vi.fn(() => Promise.resolve({ response: \"9000\" }));\n const api = mockServerScreenApi(aClient({ sendApdu }), \"device-1\");\n\n await expect(api.openApp?.(\"a\".repeat(256))).rejects.toThrow(\"too long\");\n expect(sendApdu).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAoC,iCAGpC,MAAMC,EAAWC,IACd,CACC,cAAe,GAAG,GAAG,EACrB,UAAW,GAAG,GAAG,EACjB,YAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAC,EAC1C,YAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAC,EAC1C,GAAGA,CACL,GAEF,SAAS,sBAAuB,IAAM,CACpC,GAAG,wCAAyC,SAAY,CACtD,MAAMC,EAAO,IAAI,KAAK,CAAC,KAAK,CAAC,EACvBC,EAASH,EAAQ,CACrB,cAAe,GAAG,GAAG,IAAM,QAAQ,QAAQE,CAAI,CAAC,CAClD,CAAC,EAED,MAAM,UACJ,uBAAoBC,EAAQ,UAAU,EAAE,WAAW,CACrD,EAAE,SAAS,KAAKD,CAAI,EACpB,OAAOC,EAAO,aAAa,EAAE,qBAAqB,UAAU,CAC9D,CAAC,EAED,GAAG,kEAAmE,SAAY,CAChF,MAAMA,EAASH,EAAQ,CACrB,cAAe,GAAG,GAAG,IAAM,QAAQ,OAAO,CAAE,OAAQ,GAAI,CAAC,CAAC,CAC5D,CAAC,EAED,MAAM,UACJ,uBAAoBG,EAAQ,UAAU,EAAE,WAAW,CACrD,EAAE,SAAS,SAAS,CACtB,CAAC,EAED,GAAG,wCAAyC,SAAY,CACtD,MAAMC,EAAQ,OAAO,OAAO,IAAI,MAAM,MAAM,EAAG,CAAE,OAAQ,GAAI,CAAC,EACxDD,EAASH,EAAQ,CACrB,cAAe,GAAG,GAAG,IAAM,QAAQ,OAAOI,CAAK,CAAC,CAClD,CAAC,EAED,MAAM,UACJ,uBAAoBD,EAAQ,UAAU,EAAE,WAAW,CACrD,EAAE,QAAQ,KAAKC,CAAK,CACtB,CAAC,EAED,GAAG,qCAAsC,SAAY,CACnD,MAAMC,EAAS,CAAE,GAAI,WAAY,YAAa,OAAQ,EAChDF,EAASH,EAAQ,CAAE,UAAW,GAAG,GAAG,IAAM,QAAQ,QAAQK,CAAM,CAAC,CAAE,CAAC,EAE1E,MAAM,UACJ,uBAAoBF,EAAQ,UAAU,EAAE,OAAO,CACjD,EAAE,SAAS,QAAQ,CACjB,KAAM,UACN,OAAAE,CACF,CAAC,CACH,CAAC,EAED,GAAG,6CAA8C,SAAY,CAC3D,MAAMF,EAASH,EAAQ,CAAC,CAAC,EACnBM,KAAM,uBAAoBH,EAAQ,UAAU,EAElD,MAAMG,EAAI,YAAY,OAAQ,OAAO,EACrC,MAAMA,EAAI,MAAM,GAAI,GAAI,SAAS,EAEjC,OAAOH,EAAO,WAAW,EAAE,qBACzB,WACA,OACA,OACF,EACA,OAAOA,EAAO,WAAW,EAAE,qBACzB,WACA,GACA,GACA,SACF,CACF,CAAC,EAED,GAAG,uBAAwB,SAAY,CACrC,MAAMI,EAAW,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,SAAU,MAAO,CAAC,CAAC,EAGlE,QAFY,uBAAoBP,EAAQ,CAAE,SAAAO,CAAS,CAAC,EAAG,UAAU,EAEvD,UAAU,SAAS,EAE7B,OAAOA,CAAQ,EAAE,qBACf,WACA,WAAW,KAAK,CACd,IACA,IACA,EACA,EACA,EACA,GAAG,IAAI,YAAY,EAAE,OAAO,SAAS,CACvC,CAAC,CACH,CACF,CAAC,EAED,GAAG,0CAA2C,SAAY,CACxD,MAAMA,EAAW,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,SAAU,MAAO,CAAC,CAAC,EAC5DD,KAAM,uBAAoBN,EAAQ,CAAE,SAAAO,CAAS,CAAC,EAAG,UAAU,EAEjE,MAAM,OAAOD,EAAI,UAAU,SAAS,CAAC,EAAE,QAAQ,QAAQ,MAAM,CAC/D,CAAC,EAED,GAAG,4CAA6C,SAAY,CAC1D,MAAMC,EAAW,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,SAAU,MAAO,CAAC,CAAC,EAC5DD,KAAM,uBAAoBN,EAAQ,CAAE,SAAAO,CAAS,CAAC,EAAG,UAAU,EAEjE,MAAM,OAAOD,EAAI,UAAU,IAAI,OAAO,GAAG,CAAC,CAAC,EAAE,QAAQ,QAAQ,UAAU,EACvE,OAAOC,CAAQ,EAAE,IAAI,iBAAiB,CACxC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_mockServerScreenApi", "aClient", "overrides", "blob", "client", "error", "device", "api", "sendApdu"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var u=(o,e,c,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of s(e))!p.call(o,t)&&t!==c&&i(o,t,{get:()=>e[t],enumerable:!(n=r(e,t))||n.enumerable});return o};var S=o=>u(i({},"__esModule",{value:!0}),o);var l={};module.exports=S(l);
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type Device,\n type MockClient,\n type SpeculosAction,\n type SpeculosButton,\n} from \"@ledgerhq/device-mockserver-client\";\n\n/**\n * The MockClient calls this library makes. Picking them drops the class's\n * private fields, so a client from another copy of the package still fits.\n */\nexport type MockServerClient = Pick<\n MockClient,\n \"getDevice\" | \"getScreenshot\" | \"pressButton\" | \"touchScreen\" | \"sendApdu\"\n>;\n\n/**\n * How the screen is reached. The mock server proxies to the Speculos instance\n * backing a device and a Speculos transport talks to one directly, but both\n * answer the same calls.\n */\nexport interface ScreenApi {\n /** Resolves null when there is no screen to capture right now. */\n screenshot(): Promise<Blob | null>;\n /** What to show while `screenshot` keeps resolving null. */\n idle?(): Promise<DeviceScreenState>;\n pressButton(button: SpeculosButton, action: SpeculosAction): Promise<void>;\n /** Coordinates in device screen pixels. */\n touch(x: number, y: number, action: SpeculosAction): Promise<void>;\n /** Omitted by apis whose device always runs an app. */\n openApp?(appName: string): Promise<void>;\n}\n\n/**\n * Press and release are separate so a hold reaches the device as a hold: Stax\n * and Flex gate their confirmations behind one.\n */\nexport interface DeviceScreenInput {\n pressButton(button: SpeculosButton, action: SpeculosAction): void;\n touch(x: number, y: number, action: SpeculosAction): void;\n}\n\nexport type DeviceScreenState =\n | { kind: \"loading\" }\n /** No app runs, so no Speculos instance: the device record stands in. */\n | { kind: \"os-info\"; device: Device }\n /** `src` is whatever the platform's `toImageSource` made of the frame. */\n | { kind: \"image\"; src: string; input: DeviceScreenInput }\n | { kind: \"error\"; message: string };\n\n/**\n * What a screen needs from the platform drawing it. Polling restarts whenever\n * this object changes, so hosts pass a module-level constant.\n */\nexport interface ScreenPlatform {\n /** Turns a screenshot into a source the platform's image element shows. */\n toImageSource(screenshot: Blob): Promise<string>;\n /** Frees a source once a newer frame or no frame replaces it. */\n releaseImageSource?(source: string): void;\n /** Polling skips its turn while the screen is out of sight. */\n isHidden(): boolean;\n}\n"],
|
|
5
|
+
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
|
+
"names": ["types_exports", "__toCommonJS"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var p=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var i=(o,t)=>{for(var e in t)p(o,e,{get:t[e],enumerable:!0})},r=(o,t,e,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of s(t))!d.call(o,u)&&u!==e&&p(o,u,{get:()=>t[u],enumerable:!(l=c(t,u))||l.enumerable});return o};var B=o=>r(p({},"__esModule",{value:!0}),o);var S={};i(S,{useButtonHold:()=>H});module.exports=B(S);var n=require("./useHold");const H=o=>(0,n.useHold)(o);0&&(module.exports={useButtonHold});
|
|
2
|
+
//# sourceMappingURL=useButtonHold.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useButtonHold.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type SpeculosAction,\n type SpeculosButton,\n} from \"@ledgerhq/device-mockserver-client\";\n\nimport { type Hold, useHold } from \"./useHold\";\n\nexport type ButtonHold = Hold<SpeculosButton>;\n\n/** A physical button's down and up, as the actions the device gets. */\nexport const useButtonHold = (\n onPress: (button: SpeculosButton, action: SpeculosAction) => void,\n): ButtonHold => useHold(onPress);\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAmC,qBAK5B,MAAMF,EACXG,MACe,WAAQA,CAAO",
|
|
6
|
+
"names": ["useButtonHold_exports", "__export", "useButtonHold", "__toCommonJS", "import_useHold", "onPress"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var c=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var p=(t,e,a,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!v.call(t,n)&&n!==a&&i(t,n,{get:()=>e[n],enumerable:!(s=m(e,n))||s.enumerable});return t};var B=(t,e,a)=>(a=t!=null?c(u(t)):{},p(e||!t||!t.__esModule?i(a,"default",{value:t,enumerable:!0}):a,t));var o=B(require("react")),r=require("react-dom/client"),d=require("./useButtonHold"),l=require("./useHold");Object.assign(globalThis,{IS_REACT_ACT_ENVIRONMENT:!0});describe("useButtonHold",()=>{let t,e;const a=vi.fn(),s=()=>(e=(0,d.useButtonHold)(a),null);beforeEach(()=>{vi.useFakeTimers(),a.mockReset(),t=(0,r.createRoot)(document.createElement("div")),(0,o.act)(()=>t.render(o.default.createElement(s,null)))}),afterEach(()=>{(0,o.act)(()=>t.unmount()),vi.useRealTimers()}),it("sends a quick click as one press-and-release",()=>{e.hold("left"),vi.advanceTimersByTime(l.HOLD_THRESHOLD_MS-1),e.release(),expect(a).toHaveBeenCalledExactlyOnceWith("left","press-and-release")}),it("sends a hold as a press then a release",()=>{e.hold("both"),vi.advanceTimersByTime(l.HOLD_THRESHOLD_MS),expect(a).toHaveBeenCalledExactlyOnceWith("both","press"),e.release(),expect(a).toHaveBeenLastCalledWith("both","release"),expect(a).toHaveBeenCalledTimes(2)}),it("handles one button at a time",()=>{e.hold("left"),e.hold("right"),e.release(),expect(a).toHaveBeenCalledExactlyOnceWith("left","press-and-release")}),it("ignores a release with nothing held",()=>{e.release(),expect(a).not.toHaveBeenCalled()}),it("releases a held button when unmounted",()=>{e.hold("right"),vi.advanceTimersByTime(l.HOLD_THRESHOLD_MS),(0,o.act)(()=>t.unmount()),t=(0,r.createRoot)(document.createElement("div")),expect(a).toHaveBeenLastCalledWith("right","release")}),it("sends nothing for a click cut short by an unmount",()=>{e.hold("right"),(0,o.act)(()=>t.unmount()),t=(0,r.createRoot)(document.createElement("div")),vi.advanceTimersByTime(l.HOLD_THRESHOLD_MS),expect(a).not.toHaveBeenCalled()})});
|
|
2
|
+
//# sourceMappingURL=useButtonHold.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useButtonHold.test.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { act } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\n\nimport { type ButtonHold, useButtonHold } from \"./useButtonHold\";\nimport { HOLD_THRESHOLD_MS } from \"./useHold\";\n\nObject.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });\n\ndescribe(\"useButtonHold\", () => {\n let root: Root;\n let buttons: ButtonHold;\n const onPress = vi.fn();\n\n const Probe: React.FC = () => {\n buttons = useButtonHold(onPress);\n return null;\n };\n\n beforeEach(() => {\n vi.useFakeTimers();\n onPress.mockReset();\n root = createRoot(document.createElement(\"div\"));\n act(() => root.render(<Probe />));\n });\n\n afterEach(() => {\n act(() => root.unmount());\n vi.useRealTimers();\n });\n\n it(\"sends a quick click as one press-and-release\", () => {\n buttons.hold(\"left\");\n vi.advanceTimersByTime(HOLD_THRESHOLD_MS - 1);\n buttons.release();\n\n expect(onPress).toHaveBeenCalledExactlyOnceWith(\n \"left\",\n \"press-and-release\",\n );\n });\n\n it(\"sends a hold as a press then a release\", () => {\n buttons.hold(\"both\");\n vi.advanceTimersByTime(HOLD_THRESHOLD_MS);\n expect(onPress).toHaveBeenCalledExactlyOnceWith(\"both\", \"press\");\n\n buttons.release();\n\n expect(onPress).toHaveBeenLastCalledWith(\"both\", \"release\");\n expect(onPress).toHaveBeenCalledTimes(2);\n });\n\n it(\"handles one button at a time\", () => {\n buttons.hold(\"left\");\n buttons.hold(\"right\");\n buttons.release();\n\n expect(onPress).toHaveBeenCalledExactlyOnceWith(\n \"left\",\n \"press-and-release\",\n );\n });\n\n it(\"ignores a release with nothing held\", () => {\n buttons.release();\n\n expect(onPress).not.toHaveBeenCalled();\n });\n\n it(\"releases a held button when unmounted\", () => {\n buttons.hold(\"right\");\n vi.advanceTimersByTime(HOLD_THRESHOLD_MS);\n\n act(() => root.unmount());\n root = createRoot(document.createElement(\"div\"));\n\n expect(onPress).toHaveBeenLastCalledWith(\"right\", \"release\");\n });\n\n it(\"sends nothing for a click cut short by an unmount\", () => {\n buttons.hold(\"right\");\n\n act(() => root.unmount());\n root = createRoot(document.createElement(\"div\"));\n vi.advanceTimersByTime(HOLD_THRESHOLD_MS);\n\n expect(onPress).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAA2B,oBAC3BC,EAAsC,4BAEtCC,EAA+C,2BAC/CC,EAAkC,qBAElC,OAAO,OAAO,WAAY,CAAE,yBAA0B,EAAK,CAAC,EAE5D,SAAS,gBAAiB,IAAM,CAC9B,IAAIC,EACAC,EACJ,MAAMC,EAAU,GAAG,GAAG,EAEhBC,EAAkB,KACtBF,KAAU,iBAAcC,CAAO,EACxB,MAGT,WAAW,IAAM,CACf,GAAG,cAAc,EACjBA,EAAQ,UAAU,EAClBF,KAAO,cAAW,SAAS,cAAc,KAAK,CAAC,KAC/C,OAAI,IAAMA,EAAK,OAAO,EAAAI,QAAA,cAACD,EAAA,IAAM,CAAE,CAAC,CAClC,CAAC,EAED,UAAU,IAAM,IACd,OAAI,IAAMH,EAAK,QAAQ,CAAC,EACxB,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,+CAAgD,IAAM,CACvDC,EAAQ,KAAK,MAAM,EACnB,GAAG,oBAAoB,oBAAoB,CAAC,EAC5CA,EAAQ,QAAQ,EAEhB,OAAOC,CAAO,EAAE,gCACd,OACA,mBACF,CACF,CAAC,EAED,GAAG,yCAA0C,IAAM,CACjDD,EAAQ,KAAK,MAAM,EACnB,GAAG,oBAAoB,mBAAiB,EACxC,OAAOC,CAAO,EAAE,gCAAgC,OAAQ,OAAO,EAE/DD,EAAQ,QAAQ,EAEhB,OAAOC,CAAO,EAAE,yBAAyB,OAAQ,SAAS,EAC1D,OAAOA,CAAO,EAAE,sBAAsB,CAAC,CACzC,CAAC,EAED,GAAG,+BAAgC,IAAM,CACvCD,EAAQ,KAAK,MAAM,EACnBA,EAAQ,KAAK,OAAO,EACpBA,EAAQ,QAAQ,EAEhB,OAAOC,CAAO,EAAE,gCACd,OACA,mBACF,CACF,CAAC,EAED,GAAG,sCAAuC,IAAM,CAC9CD,EAAQ,QAAQ,EAEhB,OAAOC,CAAO,EAAE,IAAI,iBAAiB,CACvC,CAAC,EAED,GAAG,wCAAyC,IAAM,CAChDD,EAAQ,KAAK,OAAO,EACpB,GAAG,oBAAoB,mBAAiB,KAExC,OAAI,IAAMD,EAAK,QAAQ,CAAC,EACxBA,KAAO,cAAW,SAAS,cAAc,KAAK,CAAC,EAE/C,OAAOE,CAAO,EAAE,yBAAyB,QAAS,SAAS,CAC7D,CAAC,EAED,GAAG,oDAAqD,IAAM,CAC5DD,EAAQ,KAAK,OAAO,KAEpB,OAAI,IAAMD,EAAK,QAAQ,CAAC,EACxBA,KAAO,cAAW,SAAS,cAAc,KAAK,CAAC,EAC/C,GAAG,oBAAoB,mBAAiB,EAExC,OAAOE,CAAO,EAAE,IAAI,iBAAiB,CACvC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_react", "import_client", "import_useButtonHold", "import_useHold", "root", "buttons", "onPress", "Probe", "React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var u in e)s(t,u,{get:e[u],enumerable:!0})},H=(t,e,u,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!T.call(t,n)&&n!==u&&s(t,n,{get:()=>e[n],enumerable:!(o=f(e,n))||o.enumerable});return t};var y=t=>H(s({},"__esModule",{value:!0}),t);var g={};m(g,{HOLD_THRESHOLD_MS:()=>i,useHold:()=>b});module.exports=y(g);var r=require("react");const i=150;function b(t){const e=(0,r.useRef)(null),u=(0,r.useRef)(null),o=(0,r.useRef)(t);o.current=t;const n=(0,r.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null)},[]),c=(0,r.useCallback)(l=>{if(!o.current||e.current)return!1;const d={target:l,pressed:!1};return e.current=d,u.current=setTimeout(()=>{d.pressed=!0,o.current?.(l,"press")},i),!0},[]),a=(0,r.useCallback)(()=>{const l=e.current;return l?(e.current=null,n(),o.current?.(l.target,l.pressed?"release":"press-and-release"),!0):!1},[n]);return(0,r.useEffect)(()=>()=>{const l=e.current;e.current=null,n(),l?.pressed&&o.current?.(l.target,"release")},[n]),(0,r.useMemo)(()=>({hold:c,release:a}),[c,a])}0&&(module.exports={HOLD_THRESHOLD_MS,useHold});
|
|
2
|
+
//# sourceMappingURL=useHold.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useHold.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { type SpeculosAction } from \"@ledgerhq/device-mockserver-client\";\n\n/**\n * How long a button or finger stays down before the interaction counts as a\n * hold. A click sent as a separate press and release is two requests the\n * device can receive in either order, and the emulator only sees what is down\n * when its event loop samples it, so a click that beats the loop is dropped:\n * a quick tap, or a chord of both buttons. One press-and-release leaves the\n * timing to the emulator.\n */\nexport const HOLD_THRESHOLD_MS = 150;\n\ninterface Held<T> {\n target: T;\n pressed: boolean;\n}\n\nexport interface Hold<T> {\n /** Went down. False when ignored: no handler, or something is held. */\n hold(target: T): boolean;\n /** Went up. False when nothing was held. */\n release(): boolean;\n}\n\n/**\n * Turns a button's or a finger's down and up into the actions the device\n * gets: a quick click as one press-and-release, a longer hold as a press then\n * a release. Whatever is still pressed on unmount is released.\n */\nexport function useHold<T>(\n onAction: ((target: T, action: SpeculosAction) => void) | undefined,\n): Hold<T> {\n const held = useRef<Held<T> | null>(null);\n const holdTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const actionRef = useRef(onAction);\n actionRef.current = onAction;\n\n const clearHoldTimer = useCallback(() => {\n if (!holdTimer.current) return;\n clearTimeout(holdTimer.current);\n holdTimer.current = null;\n }, []);\n\n const hold = useCallback((target: T) => {\n if (!actionRef.current || held.current) return false;\n const entry: Held<T> = { target, pressed: false };\n held.current = entry;\n holdTimer.current = setTimeout(() => {\n entry.pressed = true;\n actionRef.current?.(target, \"press\");\n }, HOLD_THRESHOLD_MS);\n return true;\n }, []);\n\n const release = useCallback(() => {\n const entry = held.current;\n if (!entry) return false;\n held.current = null;\n clearHoldTimer();\n actionRef.current?.(\n entry.target,\n entry.pressed ? \"release\" : \"press-and-release\",\n );\n return true;\n }, [clearHoldTimer]);\n\n useEffect(\n () => () => {\n const entry = held.current;\n held.current = null;\n clearHoldTimer();\n if (entry?.pressed) actionRef.current?.(entry.target, \"release\");\n },\n [clearHoldTimer],\n );\n\n return useMemo(() => ({ hold, release }), [hold, release]);\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAwD,iBAWjD,MAAMH,EAAoB,IAmB1B,SAASC,EACdG,EACS,CACT,MAAMC,KAAO,UAAuB,IAAI,EAClCC,KAAY,UAA6C,IAAI,EAC7DC,KAAY,UAAOH,CAAQ,EACjCG,EAAU,QAAUH,EAEpB,MAAMI,KAAiB,eAAY,IAAM,CAClCF,EAAU,UACf,aAAaA,EAAU,OAAO,EAC9BA,EAAU,QAAU,KACtB,EAAG,CAAC,CAAC,EAECG,KAAO,eAAaC,GAAc,CACtC,GAAI,CAACH,EAAU,SAAWF,EAAK,QAAS,MAAO,GAC/C,MAAMM,EAAiB,CAAE,OAAAD,EAAQ,QAAS,EAAM,EAChD,OAAAL,EAAK,QAAUM,EACfL,EAAU,QAAU,WAAW,IAAM,CACnCK,EAAM,QAAU,GAChBJ,EAAU,UAAUG,EAAQ,OAAO,CACrC,EAAGV,CAAiB,EACb,EACT,EAAG,CAAC,CAAC,EAECY,KAAU,eAAY,IAAM,CAChC,MAAMD,EAAQN,EAAK,QACnB,OAAKM,GACLN,EAAK,QAAU,KACfG,EAAe,EACfD,EAAU,UACRI,EAAM,OACNA,EAAM,QAAU,UAAY,mBAC9B,EACO,IAPY,EAQrB,EAAG,CAACH,CAAc,CAAC,EAEnB,sBACE,IAAM,IAAM,CACV,MAAMG,EAAQN,EAAK,QACnBA,EAAK,QAAU,KACfG,EAAe,EACXG,GAAO,SAASJ,EAAU,UAAUI,EAAM,OAAQ,SAAS,CACjE,EACA,CAACH,CAAc,CACjB,KAEO,WAAQ,KAAO,CAAE,KAAAC,EAAM,QAAAG,CAAQ,GAAI,CAACH,EAAMG,CAAO,CAAC,CAC3D",
|
|
6
|
+
"names": ["useHold_exports", "__export", "HOLD_THRESHOLD_MS", "useHold", "__toCommonJS", "import_react", "onAction", "held", "holdTimer", "actionRef", "clearHoldTimer", "hold", "target", "entry", "release"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},D=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!p.call(t,r)&&r!==n&&u(t,r,{get:()=>e[r],enumerable:!(i=s(e,r))||i.enumerable});return t};var a=t=>D(u({},"__esModule",{value:!0}),t);var S={};v(S,{useMockServerDevice:()=>y});module.exports=a(S);var o=require("react");const d=2e3;function y(t,e){const[n,i]=(0,o.useState)();return(0,o.useEffect)(()=>{let r=!1,c;if(i(void 0),!e)return;const f=()=>{t.getDevice(e).then(l=>{r||i(l)},()=>{r||(i(null),c=setTimeout(f,d))})};return f(),()=>{r=!0,clearTimeout(c)}},[t,e]),n}0&&(module.exports={useMockServerDevice});
|
|
2
|
+
//# sourceMappingURL=useMockServerDevice.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useMockServerDevice.ts"],
|
|
4
|
+
"sourcesContent": ["import { useEffect, useState } from \"react\";\nimport { type Device } from \"@ledgerhq/device-mockserver-client\";\n\nimport { type MockServerClient } from \"./types\";\n\nconst RETRY_MS = 2000;\n\n/**\n * The mock server's record of a device: undefined while it loads, or while no\n * device id is given, and null while it cannot be read. A failed read is\n * retried, so a transient error does not leave the device without its model.\n */\nexport function useMockServerDevice(\n client: MockServerClient,\n deviceId: string,\n): Device | null | undefined {\n const [device, setDevice] = useState<Device | null>();\n\n useEffect(() => {\n let cancelled = false;\n let retry: ReturnType<typeof setTimeout> | undefined;\n setDevice(undefined);\n if (!deviceId) return;\n\n const load = () => {\n client.getDevice(deviceId).then(\n (record) => {\n if (!cancelled) setDevice(record);\n },\n () => {\n if (cancelled) return;\n setDevice(null);\n retry = setTimeout(load, RETRY_MS);\n },\n );\n };\n load();\n\n return () => {\n cancelled = true;\n clearTimeout(retry);\n };\n }, [client, deviceId]);\n\n return device;\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAoC,iBAKpC,MAAMC,EAAW,IAOV,SAASH,EACdI,EACAC,EAC2B,CAC3B,KAAM,CAACC,EAAQC,CAAS,KAAI,YAAwB,EAEpD,sBAAU,IAAM,CACd,IAAIC,EAAY,GACZC,EAEJ,GADAF,EAAU,MAAS,EACf,CAACF,EAAU,OAEf,MAAMK,EAAO,IAAM,CACjBN,EAAO,UAAUC,CAAQ,EAAE,KACxBM,GAAW,CACLH,GAAWD,EAAUI,CAAM,CAClC,EACA,IAAM,CACAH,IACJD,EAAU,IAAI,EACdE,EAAQ,WAAWC,EAAMP,CAAQ,EACnC,CACF,CACF,EACA,OAAAO,EAAK,EAEE,IAAM,CACXF,EAAY,GACZ,aAAaC,CAAK,CACpB,CACF,EAAG,CAACL,EAAQC,CAAQ,CAAC,EAEdC,CACT",
|
|
6
|
+
"names": ["useMockServerDevice_exports", "__export", "useMockServerDevice", "__toCommonJS", "import_react", "RETRY_MS", "client", "deviceId", "device", "setDevice", "cancelled", "retry", "load", "record"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var k=(i,n,t,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of C(n))!h.call(i,r)&&r!==t&&d(i,r,{get:()=>n[r],enumerable:!(l=f(n,r))||l.enumerable});return i};var S=(i,n,t)=>(t=i!=null?u(y(i)):{},k(n||!i||!i.__esModule?d(t,"default",{value:i,enumerable:!0}):t,i));var c=S(require("react")),m=require("react-dom/client"),p=require("./useMockServerDevice");Object.assign(globalThis,{IS_REACT_ACT_ENVIRONMENT:!0});const s={id:"device-1",device_type:"stax"};describe("useMockServerDevice",()=>{let i,n,t;const l=({client:e,deviceId:o})=>(t=(0,p.useMockServerDevice)(e,o),null),r=e=>({getDevice:vi.fn(e)}),a=(e,o="device-1")=>(0,c.act)(()=>n.render(c.default.createElement(l,{client:e,deviceId:o}))),v=()=>(0,c.act)(()=>vi.advanceTimersByTimeAsync(0));beforeEach(()=>{vi.useFakeTimers(),t=void 0,i=document.createElement("div"),n=(0,m.createRoot)(i)}),afterEach(()=>{(0,c.act)(()=>n.unmount()),vi.useRealTimers()}),it("reads the device record",async()=>{const e=r(()=>Promise.resolve(s));a(e),expect(t).toBeUndefined(),await v(),expect(t).toBe(s),expect(e.getDevice).toHaveBeenCalledWith("device-1")}),it("accepts a client from another copy of the package",async()=>{class e{record=s;getDevice=vi.fn(()=>Promise.resolve(this.record));getScreenshot=vi.fn();pressButton=vi.fn();touchScreen=vi.fn();sendApdu=vi.fn()}const o=new e;a(o),await v(),expect(t).toBe(s)}),it("reads nothing without a device id",async()=>{const e=r(()=>Promise.resolve(s));a(e,""),await v(),expect(t).toBeUndefined(),expect(e.getDevice).not.toHaveBeenCalled()}),it("retries a failed read until it succeeds",async()=>{const e=vi.fn().mockRejectedValueOnce(new Error("offline")).mockResolvedValue(s),o=r(e);a(o),await v(),expect(t).toBeNull(),await(0,c.act)(()=>vi.advanceTimersByTimeAsync(2e3)),expect(t).toBe(s),expect(e).toHaveBeenCalledTimes(2)}),it("stops retrying once unmounted",async()=>{const e=r(()=>Promise.reject(new Error("offline")));a(e),await v(),(0,c.act)(()=>n.render(c.default.createElement(c.default.Fragment,null))),await(0,c.act)(()=>vi.advanceTimersByTimeAsync(1e4)),expect(e.getDevice).toHaveBeenCalledOnce()})});
|
|
2
|
+
//# sourceMappingURL=useMockServerDevice.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useMockServerDevice.test.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { act } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { type Device } from \"@ledgerhq/device-mockserver-client\";\n\nimport { type MockServerClient } from \"./types\";\nimport { useMockServerDevice } from \"./useMockServerDevice\";\n\nObject.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });\n\nconst DEVICE = { id: \"device-1\", device_type: \"stax\" } as Device;\n\ndescribe(\"useMockServerDevice\", () => {\n let container: HTMLDivElement;\n let root: Root;\n let result: Device | null | undefined;\n\n const Probe: React.FC<{ client: MockServerClient; deviceId: string }> = ({\n client,\n deviceId,\n }) => {\n result = useMockServerDevice(client, deviceId);\n return null;\n };\n const aClient = (getDevice: () => Promise<Device>) =>\n ({ getDevice: vi.fn(getDevice) }) as unknown as MockServerClient;\n const render = (client: MockServerClient, deviceId = \"device-1\") =>\n act(() => root.render(<Probe client={client} deviceId={deviceId} />));\n const flush = () => act(() => vi.advanceTimersByTimeAsync(0));\n\n beforeEach(() => {\n vi.useFakeTimers();\n result = undefined;\n container = document.createElement(\"div\");\n root = createRoot(container);\n });\n\n afterEach(() => {\n act(() => root.unmount());\n vi.useRealTimers();\n });\n\n it(\"reads the device record\", async () => {\n const client = aClient(() => Promise.resolve(DEVICE));\n\n render(client);\n expect(result).toBeUndefined();\n await flush();\n\n expect(result).toBe(DEVICE);\n expect(client.getDevice).toHaveBeenCalledWith(\"device-1\");\n });\n\n it(\"accepts a client from another copy of the package\", async () => {\n // Its own private field, as a MockClient from a second install would have:\n // only the public calls must match.\n class OtherCopyClient implements MockServerClient {\n private readonly record = DEVICE;\n getDevice = vi.fn(() => Promise.resolve(this.record));\n getScreenshot = vi.fn<MockServerClient[\"getScreenshot\"]>();\n pressButton = vi.fn<MockServerClient[\"pressButton\"]>();\n touchScreen = vi.fn<MockServerClient[\"touchScreen\"]>();\n sendApdu = vi.fn<MockServerClient[\"sendApdu\"]>();\n }\n const client = new OtherCopyClient();\n\n render(client);\n await flush();\n\n expect(result).toBe(DEVICE);\n });\n\n it(\"reads nothing without a device id\", async () => {\n const client = aClient(() => Promise.resolve(DEVICE));\n\n render(client, \"\");\n await flush();\n\n expect(result).toBeUndefined();\n expect(client.getDevice).not.toHaveBeenCalled();\n });\n\n it(\"retries a failed read until it succeeds\", async () => {\n const getDevice = vi\n .fn<() => Promise<Device>>()\n .mockRejectedValueOnce(new Error(\"offline\"))\n .mockResolvedValue(DEVICE);\n const client = aClient(getDevice);\n\n render(client);\n await flush();\n expect(result).toBeNull();\n\n await act(() => vi.advanceTimersByTimeAsync(2000));\n\n expect(result).toBe(DEVICE);\n expect(getDevice).toHaveBeenCalledTimes(2);\n });\n\n it(\"stops retrying once unmounted\", async () => {\n const client = aClient(() => Promise.reject(new Error(\"offline\")));\n\n render(client);\n await flush();\n act(() => root.render(<></>));\n await act(() => vi.advanceTimersByTimeAsync(10_000));\n\n expect(client.getDevice).toHaveBeenCalledOnce();\n });\n});\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAA2B,oBAC3BC,EAAsC,4BAItCC,EAAoC,iCAEpC,OAAO,OAAO,WAAY,CAAE,yBAA0B,EAAK,CAAC,EAE5D,MAAMC,EAAS,CAAE,GAAI,WAAY,YAAa,MAAO,EAErD,SAAS,sBAAuB,IAAM,CACpC,IAAIC,EACAC,EACAC,EAEJ,MAAMC,EAAkE,CAAC,CACvE,OAAAC,EACA,SAAAC,CACF,KACEH,KAAS,uBAAoBE,EAAQC,CAAQ,EACtC,MAEHC,EAAWC,IACd,CAAE,UAAW,GAAG,GAAGA,CAAS,CAAE,GAC3BC,EAAS,CAACJ,EAA0BC,EAAW,gBACnD,OAAI,IAAMJ,EAAK,OAAO,EAAAQ,QAAA,cAACN,EAAA,CAAM,OAAQC,EAAQ,SAAUC,EAAU,CAAE,CAAC,EAChEK,EAAQ,OAAM,OAAI,IAAM,GAAG,yBAAyB,CAAC,CAAC,EAE5D,WAAW,IAAM,CACf,GAAG,cAAc,EACjBR,EAAS,OACTF,EAAY,SAAS,cAAc,KAAK,EACxCC,KAAO,cAAWD,CAAS,CAC7B,CAAC,EAED,UAAU,IAAM,IACd,OAAI,IAAMC,EAAK,QAAQ,CAAC,EACxB,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,0BAA2B,SAAY,CACxC,MAAMG,EAASE,EAAQ,IAAM,QAAQ,QAAQP,CAAM,CAAC,EAEpDS,EAAOJ,CAAM,EACb,OAAOF,CAAM,EAAE,cAAc,EAC7B,MAAMQ,EAAM,EAEZ,OAAOR,CAAM,EAAE,KAAKH,CAAM,EAC1B,OAAOK,EAAO,SAAS,EAAE,qBAAqB,UAAU,CAC1D,CAAC,EAED,GAAG,oDAAqD,SAAY,CAGlE,MAAMO,CAA4C,CAC/B,OAASZ,EAC1B,UAAY,GAAG,GAAG,IAAM,QAAQ,QAAQ,KAAK,MAAM,CAAC,EACpD,cAAgB,GAAG,GAAsC,EACzD,YAAc,GAAG,GAAoC,EACrD,YAAc,GAAG,GAAoC,EACrD,SAAW,GAAG,GAAiC,CACjD,CACA,MAAMK,EAAS,IAAIO,EAEnBH,EAAOJ,CAAM,EACb,MAAMM,EAAM,EAEZ,OAAOR,CAAM,EAAE,KAAKH,CAAM,CAC5B,CAAC,EAED,GAAG,oCAAqC,SAAY,CAClD,MAAMK,EAASE,EAAQ,IAAM,QAAQ,QAAQP,CAAM,CAAC,EAEpDS,EAAOJ,EAAQ,EAAE,EACjB,MAAMM,EAAM,EAEZ,OAAOR,CAAM,EAAE,cAAc,EAC7B,OAAOE,EAAO,SAAS,EAAE,IAAI,iBAAiB,CAChD,CAAC,EAED,GAAG,0CAA2C,SAAY,CACxD,MAAMG,EAAY,GACf,GAA0B,EAC1B,sBAAsB,IAAI,MAAM,SAAS,CAAC,EAC1C,kBAAkBR,CAAM,EACrBK,EAASE,EAAQC,CAAS,EAEhCC,EAAOJ,CAAM,EACb,MAAMM,EAAM,EACZ,OAAOR,CAAM,EAAE,SAAS,EAExB,QAAM,OAAI,IAAM,GAAG,yBAAyB,GAAI,CAAC,EAEjD,OAAOA,CAAM,EAAE,KAAKH,CAAM,EAC1B,OAAOQ,CAAS,EAAE,sBAAsB,CAAC,CAC3C,CAAC,EAED,GAAG,gCAAiC,SAAY,CAC9C,MAAMH,EAASE,EAAQ,IAAM,QAAQ,OAAO,IAAI,MAAM,SAAS,CAAC,CAAC,EAEjEE,EAAOJ,CAAM,EACb,MAAMM,EAAM,KACZ,OAAI,IAAMT,EAAK,OAAO,EAAAQ,QAAA,gBAAAA,QAAA,aAAE,CAAG,CAAC,EAC5B,QAAM,OAAI,IAAM,GAAG,yBAAyB,GAAM,CAAC,EAEnD,OAAOL,EAAO,SAAS,EAAE,qBAAqB,CAChD,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_react", "import_client", "import_useMockServerDevice", "DEVICE", "container", "root", "result", "Probe", "client", "deviceId", "aClient", "getDevice", "render", "React", "flush", "OtherCopyClient"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var m=(e,n)=>{for(var o in n)u(e,o,{get:n[o],enumerable:!0})},v=(e,n,o,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of l(n))!a.call(e,t)&&t!==o&&u(e,t,{get:()=>n[t],enumerable:!(i=g(n,t))||i.enumerable});return e};var O=e=>v(u({},"__esModule",{value:!0}),e);var P={};m(P,{OPEN_APP_TIMEOUT_MS:()=>d,appIconUrl:()=>A,openableApps:()=>_,useOpenApp:()=>E});module.exports=O(P);var r=require("react");const T="BOLOS",d=1e4,_=e=>(e.apps??[]).filter(({name:n})=>n!==T),A=e=>`https://cdn.live.ledger.com/icons/${e.toLowerCase().replaceAll(" ","_")}.png`;function E(e){const[n,o]=(0,r.useState)(),[i,t]=(0,r.useState)(),c=(0,r.useRef)(void 0);(0,r.useEffect)(()=>()=>clearTimeout(c.current),[]);const f=(0,r.useCallback)(s=>{!e||n||(o(s),t(void 0),e(s).then(()=>{c.current=setTimeout(()=>{o(void 0),t(`${s} opened but its screen never showed up`)},d)},p=>{o(void 0),t(p instanceof Error?p.message:String(p))}))},[e,n]);return{opening:n,error:i,open:f}}0&&(module.exports={OPEN_APP_TIMEOUT_MS,appIconUrl,openableApps,useOpenApp});
|
|
2
|
+
//# sourceMappingURL=useOpenApp.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useOpenApp.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { type Device } from \"@ledgerhq/device-mockserver-client\";\n\n/** The OS reports itself as an app; it is not one the user can open. */\nconst OS_APP_NAME = \"BOLOS\";\n\nexport const OPEN_APP_TIMEOUT_MS = 10_000;\n\n/** The apps a device lists that the user can open. */\nexport const openableApps = (device: Device): NonNullable<Device[\"apps\"]> =>\n (device.apps ?? []).filter(({ name }) => name !== OS_APP_NAME);\n\n/** Ledger Live's app icons, keyed by the app's Manager API icon name. */\nexport const appIconUrl = (appName: string): string =>\n `https://cdn.live.ledger.com/icons/${appName.toLowerCase().replaceAll(\" \", \"_\")}.png`;\n\nexport interface OpenApp {\n /**\n * The app being opened. Kept on success, until the live screen replaces the\n * app list or the wait times out.\n */\n opening: string | undefined;\n error: string | undefined;\n /** Ignored without a handler, or while another app is opening. */\n open(appName: string): void;\n}\n\n/** Omitted, the apps are listed but cannot be opened. */\nexport function useOpenApp(\n onOpenApp: ((appName: string) => Promise<void>) | undefined,\n): OpenApp {\n const [opening, setOpening] = useState<string>();\n const [error, setError] = useState<string>();\n\n const openTimer = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n useEffect(() => () => clearTimeout(openTimer.current), []);\n\n const open = useCallback(\n (appName: string) => {\n if (!onOpenApp || opening) return;\n setOpening(appName);\n setError(undefined);\n onOpenApp(appName).then(\n () => {\n openTimer.current = setTimeout(() => {\n setOpening(undefined);\n setError(`${appName} opened but its screen never showed up`);\n }, OPEN_APP_TIMEOUT_MS);\n },\n (cause: unknown) => {\n setOpening(undefined);\n setError(cause instanceof Error ? cause.message : String(cause));\n },\n );\n },\n [onOpenApp, opening],\n );\n\n return { opening, error, open };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,eAAAC,EAAA,iBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAyD,iBAIzD,MAAMC,EAAc,QAEPN,EAAsB,IAGtBE,EAAgBK,IAC1BA,EAAO,MAAQ,CAAC,GAAG,OAAO,CAAC,CAAE,KAAAC,CAAK,IAAMA,IAASF,CAAW,EAGlDL,EAAcQ,GACzB,qCAAqCA,EAAQ,YAAY,EAAE,WAAW,IAAK,GAAG,CAAC,OAc1E,SAASN,EACdO,EACS,CACT,KAAM,CAACC,EAASC,CAAU,KAAI,YAAiB,EACzC,CAACC,EAAOC,CAAQ,KAAI,YAAiB,EAErCC,KAAY,UAChB,MACF,KACA,aAAU,IAAM,IAAM,aAAaA,EAAU,OAAO,EAAG,CAAC,CAAC,EAEzD,MAAMC,KAAO,eACVP,GAAoB,CACf,CAACC,GAAaC,IAClBC,EAAWH,CAAO,EAClBK,EAAS,MAAS,EAClBJ,EAAUD,CAAO,EAAE,KACjB,IAAM,CACJM,EAAU,QAAU,WAAW,IAAM,CACnCH,EAAW,MAAS,EACpBE,EAAS,GAAGL,CAAO,wCAAwC,CAC7D,EAAGT,CAAmB,CACxB,EACCiB,GAAmB,CAClBL,EAAW,MAAS,EACpBE,EAASG,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAAC,CACjE,CACF,EACF,EACA,CAACP,EAAWC,CAAO,CACrB,EAEA,MAAO,CAAE,QAAAA,EAAS,MAAAE,EAAO,KAAAG,CAAK,CAChC",
|
|
6
|
+
"names": ["useOpenApp_exports", "__export", "OPEN_APP_TIMEOUT_MS", "appIconUrl", "openableApps", "useOpenApp", "__toCommonJS", "import_react", "OS_APP_NAME", "device", "name", "appName", "onOpenApp", "opening", "setOpening", "error", "setError", "openTimer", "open", "cause"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var l=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var h=(t,e,s,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of v(e))!B.call(t,o)&&o!==s&&a(t,o,{get:()=>e[o],enumerable:!(p=m(e,o))||p.enumerable});return t};var g=(t,e,s)=>(s=t!=null?l(u(t)):{},h(e||!t||!t.__esModule?a(s,"default",{value:t,enumerable:!0}):s,t));var c=g(require("react")),d=require("react-dom/client"),i=require("./useOpenApp");Object.assign(globalThis,{IS_REACT_ACT_ENVIRONMENT:!0});describe("openableApps",()=>{it("lists the installed apps, without the OS",()=>{const t={apps:[{name:"BOLOS",version:"1.0.0"},{name:"Bitcoin",version:"2.5.0"}]};expect((0,i.openableApps)(t)).toEqual([{name:"Bitcoin",version:"2.5.0"}])}),it("lists nothing for a device without apps",()=>{expect((0,i.openableApps)({})).toEqual([])})});describe("appIconUrl",()=>{it("points at Ledger Live's icon for the app",()=>{expect((0,i.appIconUrl)("Ethereum Classic")).toBe("https://cdn.live.ledger.com/icons/ethereum_classic.png")})});describe("useOpenApp",()=>{let t,e;const s=({onOpenApp:n})=>(e=(0,i.useOpenApp)(n),null),p=n=>(0,c.act)(()=>t.render(c.default.createElement(s,{onOpenApp:n}))),o=n=>(0,c.act)(()=>e.open(n)),r=(n=0)=>(0,c.act)(()=>vi.advanceTimersByTimeAsync(n));beforeEach(()=>{vi.useFakeTimers(),t=(0,d.createRoot)(document.createElement("div"))}),afterEach(()=>{(0,c.act)(()=>t.unmount()),vi.useRealTimers()}),it("keeps the app as opening once the device accepted it",async()=>{const n=vi.fn(()=>Promise.resolve());p(n),o("Bitcoin"),await r(),expect(n).toHaveBeenCalledWith("Bitcoin"),expect(e.opening).toBe("Bitcoin"),expect(e.error).toBeUndefined()}),it("opens one app at a time",async()=>{const n=vi.fn(()=>Promise.resolve());p(n),o("Bitcoin"),o("Ethereum"),await r(),expect(n).toHaveBeenCalledOnce()}),it("says why an app could not be opened",async()=>{p(()=>Promise.reject(new Error("Could not open Bitcoin (6807)"))),o("Bitcoin"),await r(),expect(e.opening).toBeUndefined(),expect(e.error).toBe("Could not open Bitcoin (6807)")}),it("gives up when an opened app never shows its screen",async()=>{p(()=>Promise.resolve()),o("Bitcoin"),await r(i.OPEN_APP_TIMEOUT_MS),expect(e.opening).toBeUndefined(),expect(e.error).toBe("Bitcoin opened but its screen never showed up")}),it("opens nothing without a handler",()=>{p(),o("Bitcoin"),expect(e.opening).toBeUndefined()})});
|
|
2
|
+
//# sourceMappingURL=useOpenApp.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useOpenApp.test.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { act } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { type Device } from \"@ledgerhq/device-mockserver-client\";\n\nimport {\n appIconUrl,\n OPEN_APP_TIMEOUT_MS,\n openableApps,\n type OpenApp,\n useOpenApp,\n} from \"./useOpenApp\";\n\nObject.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });\n\ndescribe(\"openableApps\", () => {\n it(\"lists the installed apps, without the OS\", () => {\n const device = {\n apps: [\n { name: \"BOLOS\", version: \"1.0.0\" },\n { name: \"Bitcoin\", version: \"2.5.0\" },\n ],\n } as Device;\n\n expect(openableApps(device)).toEqual([\n { name: \"Bitcoin\", version: \"2.5.0\" },\n ]);\n });\n\n it(\"lists nothing for a device without apps\", () => {\n expect(openableApps({} as Device)).toEqual([]);\n });\n});\n\ndescribe(\"appIconUrl\", () => {\n it(\"points at Ledger Live's icon for the app\", () => {\n expect(appIconUrl(\"Ethereum Classic\")).toBe(\n \"https://cdn.live.ledger.com/icons/ethereum_classic.png\",\n );\n });\n});\n\ndescribe(\"useOpenApp\", () => {\n let root: Root;\n let result: OpenApp;\n\n const Probe: React.FC<{ onOpenApp?: (name: string) => Promise<void> }> = ({\n onOpenApp,\n }) => {\n result = useOpenApp(onOpenApp);\n return null;\n };\n const render = (onOpenApp?: (name: string) => Promise<void>) =>\n act(() => root.render(<Probe onOpenApp={onOpenApp} />));\n const open = (name: string) => act(() => result.open(name));\n const wait = (ms = 0) => act(() => vi.advanceTimersByTimeAsync(ms));\n\n beforeEach(() => {\n vi.useFakeTimers();\n root = createRoot(document.createElement(\"div\"));\n });\n\n afterEach(() => {\n act(() => root.unmount());\n vi.useRealTimers();\n });\n\n it(\"keeps the app as opening once the device accepted it\", async () => {\n const onOpenApp = vi.fn(() => Promise.resolve());\n render(onOpenApp);\n\n open(\"Bitcoin\");\n await wait();\n\n expect(onOpenApp).toHaveBeenCalledWith(\"Bitcoin\");\n expect(result.opening).toBe(\"Bitcoin\");\n expect(result.error).toBeUndefined();\n });\n\n it(\"opens one app at a time\", async () => {\n const onOpenApp = vi.fn(() => Promise.resolve());\n render(onOpenApp);\n\n open(\"Bitcoin\");\n open(\"Ethereum\");\n await wait();\n\n expect(onOpenApp).toHaveBeenCalledOnce();\n });\n\n it(\"says why an app could not be opened\", async () => {\n render(() => Promise.reject(new Error(\"Could not open Bitcoin (6807)\")));\n\n open(\"Bitcoin\");\n await wait();\n\n expect(result.opening).toBeUndefined();\n expect(result.error).toBe(\"Could not open Bitcoin (6807)\");\n });\n\n it(\"gives up when an opened app never shows its screen\", async () => {\n render(() => Promise.resolve());\n\n open(\"Bitcoin\");\n await wait(OPEN_APP_TIMEOUT_MS);\n\n expect(result.opening).toBeUndefined();\n expect(result.error).toBe(\"Bitcoin opened but its screen never showed up\");\n });\n\n it(\"opens nothing without a handler\", () => {\n render();\n\n open(\"Bitcoin\");\n\n expect(result.opening).toBeUndefined();\n });\n});\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAA2B,oBAC3BC,EAAsC,4BAGtCC,EAMO,wBAEP,OAAO,OAAO,WAAY,CAAE,yBAA0B,EAAK,CAAC,EAE5D,SAAS,eAAgB,IAAM,CAC7B,GAAG,2CAA4C,IAAM,CACnD,MAAMC,EAAS,CACb,KAAM,CACJ,CAAE,KAAM,QAAS,QAAS,OAAQ,EAClC,CAAE,KAAM,UAAW,QAAS,OAAQ,CACtC,CACF,EAEA,UAAO,gBAAaA,CAAM,CAAC,EAAE,QAAQ,CACnC,CAAE,KAAM,UAAW,QAAS,OAAQ,CACtC,CAAC,CACH,CAAC,EAED,GAAG,0CAA2C,IAAM,CAClD,UAAO,gBAAa,CAAC,CAAW,CAAC,EAAE,QAAQ,CAAC,CAAC,CAC/C,CAAC,CACH,CAAC,EAED,SAAS,aAAc,IAAM,CAC3B,GAAG,2CAA4C,IAAM,CACnD,UAAO,cAAW,kBAAkB,CAAC,EAAE,KACrC,wDACF,CACF,CAAC,CACH,CAAC,EAED,SAAS,aAAc,IAAM,CAC3B,IAAIC,EACAC,EAEJ,MAAMC,EAAmE,CAAC,CACxE,UAAAC,CACF,KACEF,KAAS,cAAWE,CAAS,EACtB,MAEHC,EAAUD,MACd,OAAI,IAAMH,EAAK,OAAO,EAAAK,QAAA,cAACH,EAAA,CAAM,UAAWC,EAAW,CAAE,CAAC,EAClDG,EAAQC,MAAiB,OAAI,IAAMN,EAAO,KAAKM,CAAI,CAAC,EACpDC,EAAO,CAACC,EAAK,OAAM,OAAI,IAAM,GAAG,yBAAyBA,CAAE,CAAC,EAElE,WAAW,IAAM,CACf,GAAG,cAAc,EACjBT,KAAO,cAAW,SAAS,cAAc,KAAK,CAAC,CACjD,CAAC,EAED,UAAU,IAAM,IACd,OAAI,IAAMA,EAAK,QAAQ,CAAC,EACxB,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,uDAAwD,SAAY,CACrE,MAAMG,EAAY,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAC,EAC/CC,EAAOD,CAAS,EAEhBG,EAAK,SAAS,EACd,MAAME,EAAK,EAEX,OAAOL,CAAS,EAAE,qBAAqB,SAAS,EAChD,OAAOF,EAAO,OAAO,EAAE,KAAK,SAAS,EACrC,OAAOA,EAAO,KAAK,EAAE,cAAc,CACrC,CAAC,EAED,GAAG,0BAA2B,SAAY,CACxC,MAAME,EAAY,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAC,EAC/CC,EAAOD,CAAS,EAEhBG,EAAK,SAAS,EACdA,EAAK,UAAU,EACf,MAAME,EAAK,EAEX,OAAOL,CAAS,EAAE,qBAAqB,CACzC,CAAC,EAED,GAAG,sCAAuC,SAAY,CACpDC,EAAO,IAAM,QAAQ,OAAO,IAAI,MAAM,+BAA+B,CAAC,CAAC,EAEvEE,EAAK,SAAS,EACd,MAAME,EAAK,EAEX,OAAOP,EAAO,OAAO,EAAE,cAAc,EACrC,OAAOA,EAAO,KAAK,EAAE,KAAK,+BAA+B,CAC3D,CAAC,EAED,GAAG,qDAAsD,SAAY,CACnEG,EAAO,IAAM,QAAQ,QAAQ,CAAC,EAE9BE,EAAK,SAAS,EACd,MAAME,EAAK,qBAAmB,EAE9B,OAAOP,EAAO,OAAO,EAAE,cAAc,EACrC,OAAOA,EAAO,KAAK,EAAE,KAAK,+CAA+C,CAC3E,CAAC,EAED,GAAG,kCAAmC,IAAM,CAC1CG,EAAO,EAEPE,EAAK,SAAS,EAEd,OAAOL,EAAO,OAAO,EAAE,cAAc,CACvC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_react", "import_client", "import_useOpenApp", "device", "root", "result", "Probe", "onOpenApp", "render", "React", "open", "name", "wait", "ms"]
|
|
7
|
+
}
|