@ledgerhq/hw-transport-node-hid-singleton 6.26.0 → 6.26.1-monorepo.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/.turbo/turbo-build.log +12 -0
- package/CHANGELOG.md +13 -0
- package/jest.config.ts +6 -0
- package/lib/TransportNodeHid.d.ts +1 -2
- package/lib/TransportNodeHid.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/TransportNodeHid.ts +1 -1
- package/LICENSE +0 -202
- package/lib-es/TransportNodeHid.d.ts +0 -32
- package/lib-es/TransportNodeHid.d.ts.map +0 -1
- package/lib-es/TransportNodeHid.js +0 -206
- package/lib-es/TransportNodeHid.js.map +0 -1
- package/lib-es/listenDevices.d.ts +0 -12
- package/lib-es/listenDevices.d.ts.map +0 -1
- package/lib-es/listenDevices.js +0 -65
- package/lib-es/listenDevices.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0mcache hit, replaying output [2m33aa3f61bd38629b[0m
|
|
2
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0m
|
|
3
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0m> @ledgerhq/hw-transport-node-hid-singleton@6.26.0 build /Users/valmeida/projects/live/ledger-live/libs/ledgerjs/packages/hw-transport-node-hid-singleton
|
|
4
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0m> bash ../../script/build.sh
|
|
5
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0m
|
|
6
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0msrc/listenDevices.ts(2,35): error TS2307: Cannot find module '@ledgerhq/devices' or its corresponding type declarations.
|
|
7
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0msrc/listenDevices.ts(3,21): error TS2307: Cannot find module '@ledgerhq/logs' or its corresponding type declarations.
|
|
8
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0msrc/TransportNodeHid.ts(9,8): error TS2307: Cannot find module '@ledgerhq/hw-transport' or its corresponding type declarations.
|
|
9
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0msrc/TransportNodeHid.ts(10,21): error TS2307: Cannot find module '@ledgerhq/logs' or its corresponding type declarations.
|
|
10
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0msrc/TransportNodeHid.ts(11,38): error TS2307: Cannot find module '@ledgerhq/devices' or its corresponding type declarations.
|
|
11
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0msrc/TransportNodeHid.ts(12,32): error TS2307: Cannot find module '@ledgerhq/errors' or its corresponding type declarations.
|
|
12
|
+
[32m@ledgerhq/hw-transport-node-hid-singleton:build: [0m ELIFECYCLE Command failed with exit code 2.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @ledgerhq/hw-transport-node-hid-singleton
|
|
2
|
+
|
|
3
|
+
## 6.26.1-monorepo.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- test prerelease
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @ledgerhq/devices@6.24.2-monorepo.0
|
|
10
|
+
- @ledgerhq/errors@6.10.1-monorepo.0
|
|
11
|
+
- @ledgerhq/hw-transport@6.24.2-monorepo.0
|
|
12
|
+
- @ledgerhq/hw-transport-node-hid-noevents@6.24.2-monorepo.0
|
|
13
|
+
- @ledgerhq/logs@6.10.1-monorepo.0
|
package/jest.config.ts
ADDED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
3
|
-
import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
|
|
4
3
|
/**
|
|
5
4
|
* node-hid Transport implementation
|
|
6
5
|
* @example
|
|
@@ -24,7 +23,7 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
|
|
|
24
23
|
/**
|
|
25
24
|
* convenience wrapper for auto-disconnect logic
|
|
26
25
|
*/
|
|
27
|
-
static autoDisconnect(): void
|
|
26
|
+
static autoDisconnect(): Promise<void>;
|
|
28
27
|
/**
|
|
29
28
|
* globally disconnect the transport singleton
|
|
30
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransportNodeHid.d.ts","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";AACA,OAAO,wBAEN,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"TransportNodeHid.d.ts","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";AACA,OAAO,wBAEN,MAAM,0CAA0C,CAAC;AA4BlD;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,wBAAwB;IAC7E,qBAAqB,UAAS;IAC9B;;OAEG;IACH,MAAM,CAAC,WAAW,yBAAwC;IAE1D;;OAEG;IACH,MAAM,CAAC,IAAI,qBAAiC;IAE5C;OACG;IACH,MAAM,CAAC,MAAM,6DAqDX;IAEF;;OAEG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5C;;OAEG;WACU,UAAU;IASvB;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAqCjD,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI5C;;;;OAIG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-transport-node-hid-singleton",
|
|
3
|
-
"version": "6.26.0",
|
|
3
|
+
"version": "6.26.1-monorepo.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid and usb-detection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -27,20 +27,23 @@
|
|
|
27
27
|
"types": "lib/TransportNodeHid.d.ts",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ledgerhq/devices": "^6.24.
|
|
31
|
-
"@ledgerhq/errors": "^6.10.0",
|
|
32
|
-
"@ledgerhq/hw-transport": "^6.24.
|
|
33
|
-
"@ledgerhq/hw-transport-node-hid-noevents": "^6.24.
|
|
34
|
-
"@ledgerhq/logs": "^6.10.0",
|
|
30
|
+
"@ledgerhq/devices": "^6.24.2-monorepo.0",
|
|
31
|
+
"@ledgerhq/errors": "^6.10.1-monorepo.0",
|
|
32
|
+
"@ledgerhq/hw-transport": "^6.24.2-monorepo.0",
|
|
33
|
+
"@ledgerhq/hw-transport-node-hid-noevents": "^6.24.2-monorepo.0",
|
|
34
|
+
"@ledgerhq/logs": "^6.10.1-monorepo.0",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"node-hid": "2.1.1",
|
|
37
37
|
"usb-detection": "^4.13.0"
|
|
38
38
|
},
|
|
39
|
+
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
39
40
|
"scripts": {
|
|
40
41
|
"clean": "bash ../../script/clean.sh",
|
|
41
42
|
"build": "bash ../../script/build.sh",
|
|
42
43
|
"watch": "bash ../../script/watch.sh",
|
|
43
|
-
"doc": "bash ../../script/doc.sh"
|
|
44
|
+
"doc": "bash ../../script/doc.sh",
|
|
45
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
|
|
46
|
+
"test": "jest"
|
|
44
47
|
},
|
|
45
|
-
"
|
|
46
|
-
}
|
|
48
|
+
"readme": "<img src=\"https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png\" height=\"100\" />\n\n[Github](https://github.com/LedgerHQ/ledgerjs/),\n[Ledger Devs Slack](https://ledger-dev.slack.com/)\n\n## @ledgerhq/hw-transport-node-hid-singleton\n\nAllows to communicate with Ledger Hardware Wallets.\n\n**\\[Node]**/Electron **(HID)** – uses `node-hid` and `usb-detection`. Keep transport opened and re-use it as a singleton, one device at a time on a computer but more robust implementation.\n\n## API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n#### Table of Contents\n\n* [TransportNodeHidSingleton](#transportnodehidsingleton)\n * [Examples](#examples)\n * [exchange](#exchange)\n * [Parameters](#parameters)\n * [isSupported](#issupported)\n * [list](#list)\n * [listen](#listen)\n * [Parameters](#parameters-1)\n * [autoDisconnect](#autodisconnect)\n * [disconnect](#disconnect)\n * [open](#open)\n\n### TransportNodeHidSingleton\n\n**Extends TransportNodeHidNoEvents**\n\nnode-hid Transport implementation\n\n#### Examples\n\n```javascript\nimport TransportNodeHid from \"@ledgerhq/hw-transport-node-hid-singleton\";\n...\nTransportNodeHid.create().then(transport => ...)\n```\n\n#### exchange\n\nExchange with the device using APDU protocol.\n\n##### Parameters\n\n* `apdu` **[Buffer](https://nodejs.org/api/buffer.html)** \n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** a promise of apdu response\n\n#### isSupported\n\n#### list\n\n#### listen\n\n##### Parameters\n\n* `observer` **Observer\\<DescriptorEvent\\<any>>** \n\nReturns **Subscription** \n\n#### autoDisconnect\n\nconvenience wrapper for auto-disconnect logic\n\nReturns **void** \n\n#### disconnect\n\nglobally disconnect the transport singleton\n\n#### open\n\nif path=\"\" is not provided, the library will take the first device\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[TransportNodeHidSingleton](#transportnodehidsingleton)>** \n"
|
|
49
|
+
}
|
package/src/TransportNodeHid.ts
CHANGED
|
@@ -109,7 +109,7 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
|
|
|
109
109
|
/**
|
|
110
110
|
* convenience wrapper for auto-disconnect logic
|
|
111
111
|
*/
|
|
112
|
-
static async autoDisconnect(): void {
|
|
112
|
+
static async autoDisconnect(): Promise<void> {
|
|
113
113
|
if (transportInstance && !transportInstance.preventAutoDisconnect) {
|
|
114
114
|
log("hid-verbose", "triggering auto disconnect");
|
|
115
115
|
TransportNodeHidSingleton.disconnect();
|
package/LICENSE
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright {yyyy} {name of copyright owner}
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
202
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
2
|
-
import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
|
|
3
|
-
/**
|
|
4
|
-
* node-hid Transport implementation
|
|
5
|
-
* @example
|
|
6
|
-
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
|
|
7
|
-
* ...
|
|
8
|
-
* TransportNodeHid.create().then(transport => ...)
|
|
9
|
-
*/
|
|
10
|
-
export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
static isSupported: () => Promise<boolean>;
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
static list: () => Promise<any>;
|
|
19
|
-
/**
|
|
20
|
-
*/
|
|
21
|
-
static listen: (observer: Observer<DescriptorEvent<any>>) => Subscription;
|
|
22
|
-
/**
|
|
23
|
-
* globally disconnect the transport singleton
|
|
24
|
-
*/
|
|
25
|
-
static disconnect(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* if path="" is not provided, the library will take the first device
|
|
28
|
-
*/
|
|
29
|
-
static open(): Promise<TransportNodeHidSingleton>;
|
|
30
|
-
close(): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=TransportNodeHid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransportNodeHid.d.ts","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":"AACA,OAAO,wBAEN,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACb,MAAM,wBAAwB,CAAC;AAMhC;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,wBAAwB;IAC7E;;OAEG;IACH,MAAM,CAAC,WAAW,yBAAwC;IAE1D;;OAEG;IACH,MAAM,CAAC,IAAI,qBAAiC;IAE5C;OACG;IACH,MAAM,CAAC,MAAM,aAAc,SAAS,gBAAgB,GAAG,CAAC,CAAC,KAAG,YAAY,CAqDtE;IAEF;;OAEG;WACU,UAAU;IAQvB;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAoCjD,KAAK;CAIN"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
32
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var __values = (this && this.__values) || function(o) {
|
|
53
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
54
|
-
if (m) return m.call(o);
|
|
55
|
-
if (o && typeof o.length === "number") return {
|
|
56
|
-
next: function () {
|
|
57
|
-
if (o && i >= o.length) o = void 0;
|
|
58
|
-
return { value: o && o[i++], done: !o };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
62
|
-
};
|
|
63
|
-
import HID from "node-hid";
|
|
64
|
-
import TransportNodeHidNoEvents, { getDevices, } from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
65
|
-
import { log } from "@ledgerhq/logs";
|
|
66
|
-
import { identifyUSBProductId } from "@ledgerhq/devices";
|
|
67
|
-
import { CantOpenDevice } from "@ledgerhq/errors";
|
|
68
|
-
import { listenDevices } from "./listenDevices";
|
|
69
|
-
var transportInstance;
|
|
70
|
-
/**
|
|
71
|
-
* node-hid Transport implementation
|
|
72
|
-
* @example
|
|
73
|
-
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
|
|
74
|
-
* ...
|
|
75
|
-
* TransportNodeHid.create().then(transport => ...)
|
|
76
|
-
*/
|
|
77
|
-
var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
78
|
-
__extends(TransportNodeHidSingleton, _super);
|
|
79
|
-
function TransportNodeHidSingleton() {
|
|
80
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* globally disconnect the transport singleton
|
|
84
|
-
*/
|
|
85
|
-
TransportNodeHidSingleton.disconnect = function () {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
if (transportInstance) {
|
|
89
|
-
transportInstance.device.close();
|
|
90
|
-
transportInstance.emit("disconnect");
|
|
91
|
-
transportInstance = null;
|
|
92
|
-
}
|
|
93
|
-
return [2 /*return*/];
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* if path="" is not provided, the library will take the first device
|
|
99
|
-
*/
|
|
100
|
-
TransportNodeHidSingleton.open = function () {
|
|
101
|
-
return Promise.resolve().then(function () {
|
|
102
|
-
if (transportInstance) {
|
|
103
|
-
log("hid-verbose", "reusing opened transport instance");
|
|
104
|
-
return transportInstance;
|
|
105
|
-
}
|
|
106
|
-
var device = getDevices()[0];
|
|
107
|
-
if (!device)
|
|
108
|
-
throw new CantOpenDevice("no device found");
|
|
109
|
-
log("hid-verbose", "new HID transport");
|
|
110
|
-
transportInstance = new TransportNodeHidSingleton(new HID.HID(device.path));
|
|
111
|
-
var unlisten = listenDevices(function () { }, function () {
|
|
112
|
-
// assume any ledger disconnection concerns current transport
|
|
113
|
-
if (transportInstance) {
|
|
114
|
-
transportInstance.emit("disconnect");
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
var onDisconnect = function () {
|
|
118
|
-
if (!transportInstance)
|
|
119
|
-
return;
|
|
120
|
-
log("hid-verbose", "transport instance was disconnected");
|
|
121
|
-
transportInstance.off("disconnect", onDisconnect);
|
|
122
|
-
transportInstance = null;
|
|
123
|
-
unlisten();
|
|
124
|
-
};
|
|
125
|
-
transportInstance.on("disconnect", onDisconnect);
|
|
126
|
-
return transportInstance;
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
TransportNodeHidSingleton.prototype.close = function () {
|
|
130
|
-
// intentionally, a close will not effectively close the hid connection
|
|
131
|
-
return Promise.resolve();
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
TransportNodeHidSingleton.isSupported = TransportNodeHidNoEvents.isSupported;
|
|
137
|
-
/**
|
|
138
|
-
*
|
|
139
|
-
*/
|
|
140
|
-
TransportNodeHidSingleton.list = TransportNodeHidNoEvents.list;
|
|
141
|
-
/**
|
|
142
|
-
*/
|
|
143
|
-
TransportNodeHidSingleton.listen = function (observer) {
|
|
144
|
-
var unsubscribed;
|
|
145
|
-
Promise.resolve(getDevices()).then(function (devices) {
|
|
146
|
-
var e_1, _a;
|
|
147
|
-
try {
|
|
148
|
-
// this needs to run asynchronously so the subscription is defined during this phase
|
|
149
|
-
for (var devices_1 = __values(devices), devices_1_1 = devices_1.next(); !devices_1_1.done; devices_1_1 = devices_1.next()) {
|
|
150
|
-
var device = devices_1_1.value;
|
|
151
|
-
if (!unsubscribed) {
|
|
152
|
-
var deviceModel = identifyUSBProductId(device.productId);
|
|
153
|
-
observer.next({
|
|
154
|
-
type: "add",
|
|
155
|
-
descriptor: "",
|
|
156
|
-
device: {
|
|
157
|
-
name: device.deviceName
|
|
158
|
-
},
|
|
159
|
-
deviceModel: deviceModel
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
165
|
-
finally {
|
|
166
|
-
try {
|
|
167
|
-
if (devices_1_1 && !devices_1_1.done && (_a = devices_1["return"])) _a.call(devices_1);
|
|
168
|
-
}
|
|
169
|
-
finally { if (e_1) throw e_1.error; }
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
var onAdd = function (device) {
|
|
173
|
-
var deviceModel = identifyUSBProductId(device.productId);
|
|
174
|
-
observer.next({
|
|
175
|
-
type: "add",
|
|
176
|
-
descriptor: "",
|
|
177
|
-
deviceModel: deviceModel,
|
|
178
|
-
device: {
|
|
179
|
-
name: device.deviceName
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
var onRemove = function (device) {
|
|
184
|
-
var deviceModel = identifyUSBProductId(device.productId);
|
|
185
|
-
observer.next({
|
|
186
|
-
type: "remove",
|
|
187
|
-
descriptor: "",
|
|
188
|
-
deviceModel: deviceModel,
|
|
189
|
-
device: {
|
|
190
|
-
name: device.deviceName
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
var stop = listenDevices(onAdd, onRemove);
|
|
195
|
-
function unsubscribe() {
|
|
196
|
-
stop();
|
|
197
|
-
unsubscribed = true;
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
unsubscribe: unsubscribe
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
return TransportNodeHidSingleton;
|
|
204
|
-
}(TransportNodeHidNoEvents));
|
|
205
|
-
export default TransportNodeHidSingleton;
|
|
206
|
-
//# sourceMappingURL=TransportNodeHid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransportNodeHid.js","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,wBAAwB,EAAE,EAC/B,UAAU,GACX,MAAM,0CAA0C,CAAC;AAMl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AC,IAAI,CAAC;gBACZ,IAAI,EAAE,KAAK;gBACX,UAAU,EAAE,EAAE;gBACd,WAAW,aAAA;gBACX,MAAM,EAAE;oBACN,IAAI,EAAE,MAAM,CAAC,UAAU;iBACxB;aACF,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAM,QAAQ,GAAG,UAAC,MAAM;YACtB,IAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC3D,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE;gBACd,WAAW,aAAA;gBACX,MAAM,EAAE;oBACN,IAAI,EAAE,MAAM,CAAC,UAAU;iBACxB;aACF,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE5C,SAAS,WAAW;YAClB,IAAI,EAAE,CAAC;YACP,YAAY,GAAG,IAAI,CAAC;QACtB,CAAC;QAED,OAAO;YACL,WAAW,aAAA;SACZ,CAAC;IACJ,CAAC,CAAC;IAwDJ,gCAAC;CAAA,AA1HD,CAAuD,wBAAwB,GA0H9E;eA1HoB,yBAAyB"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare type Device = {
|
|
2
|
-
locationId: number;
|
|
3
|
-
vendorId: number;
|
|
4
|
-
productId: number;
|
|
5
|
-
deviceName: string;
|
|
6
|
-
manufacturer: string;
|
|
7
|
-
serialNumber: string;
|
|
8
|
-
deviceAddress: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const setUsbDebounce: (n: number) => void;
|
|
11
|
-
export declare const listenDevices: (onAdd: (arg0: Device) => void, onRemove: (arg0: Device) => void) => () => void;
|
|
12
|
-
//# sourceMappingURL=listenDevices.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listenDevices.d.ts","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAGA,oBAAY,MAAM,GAAG;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAMF,eAAO,MAAM,cAAc,MAAO,MAAM,SAEvC,CAAC;AAmBF,eAAO,MAAM,aAAa,iBACV,MAAM,KAAK,IAAI,mBACZ,MAAM,KAAK,IAAI,eAyCjC,CAAC"}
|
package/lib-es/listenDevices.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import usbDetect from "usb-detection";
|
|
2
|
-
import { ledgerUSBVendorId } from "@ledgerhq/devices";
|
|
3
|
-
import { log } from "@ledgerhq/logs";
|
|
4
|
-
var deviceToLog = function (_a) {
|
|
5
|
-
var productId = _a.productId, locationId = _a.locationId, deviceAddress = _a.deviceAddress;
|
|
6
|
-
return "productId=".concat(productId, " locationId=").concat(locationId, " deviceAddress=").concat(deviceAddress);
|
|
7
|
-
};
|
|
8
|
-
var usbDebounce = 1000;
|
|
9
|
-
export var setUsbDebounce = function (n) {
|
|
10
|
-
usbDebounce = n;
|
|
11
|
-
};
|
|
12
|
-
var monitoring = false;
|
|
13
|
-
var monitor = function () {
|
|
14
|
-
if (!monitoring) {
|
|
15
|
-
monitoring = true;
|
|
16
|
-
usbDetect.startMonitoring();
|
|
17
|
-
}
|
|
18
|
-
return function () { };
|
|
19
|
-
};
|
|
20
|
-
// No better way for now. see https://github.com/LedgerHQ/ledgerjs/issues/434
|
|
21
|
-
process.on("exit", function () {
|
|
22
|
-
if (monitoring) {
|
|
23
|
-
// redeem the monitoring so the process can be terminated.
|
|
24
|
-
usbDetect.stopMonitoring();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
export var listenDevices = function (onAdd, onRemove) {
|
|
28
|
-
var unmonitor = monitor();
|
|
29
|
-
var addEvent = "add:" + ledgerUSBVendorId;
|
|
30
|
-
var removeEvent = "remove:" + ledgerUSBVendorId;
|
|
31
|
-
var timeout;
|
|
32
|
-
var add = function (device) {
|
|
33
|
-
log("usb-detection", "add: " + deviceToLog(device));
|
|
34
|
-
if (!timeout) {
|
|
35
|
-
// a time is needed for the device to actually be connectable over HID..
|
|
36
|
-
// we also take this time to not emit the device yet and potentially cancel it if a remove happens.
|
|
37
|
-
timeout = setTimeout(function () {
|
|
38
|
-
onAdd(device);
|
|
39
|
-
timeout = null;
|
|
40
|
-
}, usbDebounce);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var remove = function (device) {
|
|
44
|
-
log("usb-detection", "remove: " + deviceToLog(device));
|
|
45
|
-
if (timeout) {
|
|
46
|
-
clearTimeout(timeout);
|
|
47
|
-
timeout = null;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
onRemove(device);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
usbDetect.on(addEvent, add);
|
|
54
|
-
usbDetect.on(removeEvent, remove);
|
|
55
|
-
return function () {
|
|
56
|
-
if (timeout)
|
|
57
|
-
clearTimeout(timeout);
|
|
58
|
-
// @ts-expect-error not all EventEmitter methods are covered in its definition file
|
|
59
|
-
usbDetect.off(addEvent, add);
|
|
60
|
-
// @ts-expect-error not all EventEmitter methods are covered in its definition file
|
|
61
|
-
usbDetect.off(removeEvent, remove);
|
|
62
|
-
unmonitor();
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=listenDevices.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listenDevices.js","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,gB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