@onekeyfe/hardware-cli 1.1.25-alpha.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/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@onekeyfe/hardware-cli",
3
+ "version": "1.1.25-alpha.0",
4
+ "description": "OneKey hardware wallet CLI for AI agent integration",
5
+ "author": "OneKey",
6
+ "license": "Apache-2.0",
7
+ "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/OneKeyHQ/hardware-js-sdk.git"
11
+ },
12
+ "bin": {
13
+ "onekey-hw": "./dist/cli.js"
14
+ },
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "scripts": {
21
+ "dev": "rimraf dist && rollup -c rollup.config.js -w",
22
+ "build": "rimraf dist && rollup -c rollup.config.js && node -e \"const f='dist/cli.js';const c=require('fs').readFileSync(f,'utf8');require('fs').writeFileSync(f,'#!/usr/bin/env node\\n'+c)\"",
23
+ "lint": "eslint .",
24
+ "lint:fix": "eslint . --fix"
25
+ },
26
+ "dependencies": {
27
+ "@onekeyfe/hd-common-connect-sdk": "1.1.25-alpha.0",
28
+ "@onekeyfe/hd-core": "1.1.25-alpha.0",
29
+ "@onekeyfe/hd-shared": "1.1.25-alpha.0",
30
+ "@onekeyfe/hd-transport-usb": "1.1.25-alpha.0",
31
+ "commander": "^12.0.0"
32
+ },
33
+ "gitHead": "8cebdb9dea32ab8bfa39c51cd695f5cd9508defa"
34
+ }
@@ -0,0 +1,28 @@
1
+ import typescript from '@rollup/plugin-typescript';
2
+ import json from '@rollup/plugin-json';
3
+ import dts from 'rollup-plugin-dts';
4
+ import commonjs from '@rollup/plugin-commonjs';
5
+
6
+ const config = [
7
+ // All source files → dist/ directory (cjs format)
8
+ // This outputs index.js, cli.js, sdk.js, chains.js all to dist/
9
+ // so cli.js can require('./sdk') and require('./chains')
10
+ {
11
+ input: {
12
+ index: './src/index.ts',
13
+ cli: './src/cli.ts',
14
+ sdk: './src/sdk.ts',
15
+ chains: './src/chains.ts',
16
+ },
17
+ output: [{ dir: 'dist', format: 'cjs' }],
18
+ plugins: [typescript(), commonjs(), json()],
19
+ },
20
+ // Type declarations
21
+ {
22
+ input: './src/index.ts',
23
+ output: { file: 'dist/index.d.ts', format: 'es' },
24
+ plugins: [dts()],
25
+ },
26
+ ];
27
+
28
+ export default config;
@@ -0,0 +1,191 @@
1
+ ---
2
+ name: hardware-device
3
+ description: OneKey hardware wallet device management. Use whenever the user
4
+ wants to search for, connect to, or check the status of their OneKey
5
+ hardware wallet device. Also triggered as a pre-check before any signing
6
+ or firmware operation to ensure a device is connected and ready.
7
+ keywords: [device, connect, search, hardware, onekey, status, features, disconnect]
8
+ ---
9
+
10
+ ## Pre-flight Checks
11
+
12
+ Every time before running any `onekey-hw` command, follow these steps in order.
13
+ Do not echo routine command output to the user; only provide a brief status
14
+ update when installing, updating, or handling a failure.
15
+
16
+ 1. **Check CLI installed**: Run `onekey-hw --version`.
17
+ - Not found → install: `npm install -g @onekeyfe/hardware-cli`
18
+ - Install failed → STOP, point to manual install docs.
19
+
20
+ 2. **Check version is latest** (once per session):
21
+ - Fetch latest: `npm view @onekeyfe/hardware-cli version`
22
+ - Compare with local `onekey-hw --version`
23
+ - Local version behind → **BLOCK operation**, run `npm update -g @onekeyfe/hardware-cli`
24
+ - Update failed → STOP, suggest manual update.
25
+ - Update succeeded → continue with original command.
26
+
27
+ ## Device Interaction Model
28
+
29
+ **CRITICAL: Most `onekey-hw` commands block while waiting for physical interaction
30
+ on the hardware device (PIN entry, button confirmation, address verification).
31
+ You MUST inform the user BEFORE running the command.**
32
+
33
+ ### How It Works
34
+
35
+ 1. **Before running the command** → Tell the user what device interaction to expect.
36
+ 2. **Run the command** → It blocks (up to 60s) while waiting for the user to act on the device.
37
+ The user sees real-time `[onekey-hw]` status messages in their terminal (via stderr).
38
+ 3. **Command completes** → You see the full output and present the result.
39
+
40
+ ### Device Interaction Types
41
+
42
+ | Stderr Message | What User Must Do | When It Happens |
43
+ |---|---|---|
44
+ | `[onekey-hw] Please enter PIN on your device screen...` | Enter PIN on device touchscreen | First operation after device lock/connect |
45
+ | `[onekey-hw] Please confirm the action on your device...` | Press confirm button on device | Address display, signing, settings changes |
46
+ | `[onekey-hw] Passphrase required for hidden wallet.` | Enter passphrase on device | When accessing a hidden wallet |
47
+
48
+ ### Timeout Guidance
49
+
50
+ - Set Bash tool `timeout` to at least `120000` (120s) for any command that requires
51
+ device interaction (signing, address with `--show-on-device`, PIN changes, etc.)
52
+ - `search` does NOT require device interaction — default timeout is fine.
53
+ - If a command times out, the user likely did not respond on the device — do NOT retry
54
+ automatically. Ask the user if they want to try again.
55
+
56
+ ### Example Interaction Pattern
57
+
58
+ ```
59
+ Agent → User: "I'm going to request your ETH address from the device.
60
+ You may need to enter your PIN and confirm on the device screen."
61
+ Agent → Bash: onekey-hw get-address --chain evm --connect-id <id> (timeout: 120000)
62
+ [user sees in terminal: "[onekey-hw] Please enter PIN on your device screen..."]
63
+ [user enters PIN on device]
64
+ [user sees in terminal: "[onekey-hw] Please confirm the action on your device..."]
65
+ [user confirms on device]
66
+ Agent ← result: { success: true, payload: { address: "0x..." } }
67
+ Agent → User: "Your ETH address is 0x..."
68
+ ```
69
+
70
+ ## Security Rules — ABSOLUTE
71
+
72
+ - NEVER expose device seeds, mnemonics, or private keys in any output.
73
+ - All signing operations REQUIRE physical confirmation on the hardware device.
74
+ - NEVER bypass device confirmation prompts — if the device is waiting for user
75
+ confirmation, inform the user and wait.
76
+ - NEVER attempt to brute-force PINs or passphrases.
77
+ - Treat all device state information (features, serial numbers) as sensitive —
78
+ do not share externally without user consent.
79
+
80
+ ## Parameter Rules
81
+
82
+ ### Device Identification
83
+
84
+ - `--connect-id`: Connection identifier from `search` results.
85
+ - `--device-id`: Persistent device identifier from `getFeatures`.
86
+ - When multiple devices connected, ALWAYS ask user to select.
87
+
88
+ ## Commands
89
+
90
+ ### `onekey-hw search`
91
+
92
+ Search for connected OneKey hardware wallet devices.
93
+ **Does NOT require device interaction — no PIN or confirmation needed.**
94
+
95
+ ```bash
96
+ onekey-hw search [--timeout <ms>]
97
+ ```
98
+
99
+ | Parameter | Required | Description |
100
+ |---|---|---|
101
+ | `--timeout` | No | Search timeout in milliseconds (default: 10000) |
102
+
103
+ **Returns:**
104
+ ```json
105
+ {
106
+ "success": true,
107
+ "payload": [
108
+ {
109
+ "connectId": "PRC49J0370A",
110
+ "name": "OneKey Pro",
111
+ "deviceType": "pro"
112
+ }
113
+ ]
114
+ }
115
+ ```
116
+
117
+ **Agent notes:**
118
+ - Always run `search` before any device operation if no `connectId` is known.
119
+ - If no devices found, suggest: check USB cable, unlock device, try a different USB port.
120
+ - Multiple devices → present list, ask user to select.
121
+
122
+ ### `onekey-hw status`
123
+
124
+ Get detailed device features and current status.
125
+ **May require PIN entry on device if device is locked.**
126
+
127
+ ```bash
128
+ onekey-hw status [--connect-id <id>]
129
+ ```
130
+
131
+ **Agent notes:**
132
+ - Use this to verify device state before any operation.
133
+ - If `initialized` is false, guide user through device setup.
134
+ - If `needsBackup` is true, strongly recommend backup before any signing.
135
+ - If `bootloaderMode` is true, only firmware operations are available.
136
+ - **Warn user before running:** "You may need to enter your PIN on the device."
137
+
138
+ ### `onekey-hw lock`
139
+
140
+ Lock the device (require PIN to unlock).
141
+
142
+ ```bash
143
+ onekey-hw lock [--connect-id <id>]
144
+ ```
145
+
146
+ ## Workflows
147
+
148
+ ### First Connection
149
+
150
+ ```
151
+ User: "Connect my OneKey hardware wallet"
152
+
153
+ Step 1 — Search for devices (no device interaction needed)
154
+ → onekey-hw search --json
155
+ → If no devices found, guide troubleshooting (USB cable, unlock, different port)
156
+
157
+ Step 2 — Tell user what to expect
158
+ → "Found your OneKey Pro. I'll check its status now — you may need to enter
159
+ your PIN on the device."
160
+
161
+ Step 3 — Check device status (may need PIN)
162
+ → onekey-hw status --connect-id <id> [timeout: 120000]
163
+ → Report: model, firmware version, PIN status, backup status
164
+ ```
165
+
166
+ ### Troubleshooting Connection
167
+
168
+ ```
169
+ User: "My device won't connect"
170
+
171
+ Step 1 — Search with extended timeout
172
+ → onekey-hw search --timeout 30000
173
+
174
+ Step 2 — Guide the user:
175
+ - Is the device powered on and unlocked?
176
+ - Try a different USB cable or port
177
+ - On Linux, check udev rules for HID device permissions
178
+ ```
179
+
180
+ ## When To Use
181
+
182
+ - User asks to connect, find, or search for their hardware wallet.
183
+ - User asks about device status, firmware version, or device info.
184
+ - Pre-check before any signing or firmware operation.
185
+ - User reports connection issues.
186
+
187
+ ## When NOT To Use
188
+
189
+ - User wants to sign a transaction → use `hardware-signing`.
190
+ - User wants to update firmware → use `hardware-firmware`.
191
+ - User wants to change PIN or passphrase → use `hardware-security`.
@@ -0,0 +1,163 @@
1
+ ---
2
+ name: hardware-firmware
3
+ description: OneKey hardware wallet firmware management. Use whenever the user
4
+ wants to check for firmware updates, update their device firmware (system
5
+ or BLE), check bootloader status, or verify firmware compatibility.
6
+ keywords: [firmware, update, version, upgrade, bootloader, ble, bluetooth]
7
+ ---
8
+
9
+ ## Pre-flight Checks
10
+
11
+ Every time before running any `onekey-hw` command, follow these steps in order.
12
+
13
+ 1. **Check CLI installed**: Run `onekey-hw --version`.
14
+ - Not found → install: `npm install -g @onekeyfe/hardware-cli`
15
+
16
+ 2. **Check device connected**: Run `onekey-hw search --json`.
17
+ - No device → guide troubleshooting (USB cable, unlock device, different port).
18
+
19
+ ## Device Interaction — IMPORTANT
20
+
21
+ **Firmware commands block while waiting for device interaction (PIN, confirmation).**
22
+ Always warn the user before running: "You may need to enter your PIN and confirm
23
+ on the device." Use `timeout: 300000` (5 minutes) for firmware update commands —
24
+ updates take 1-3 minutes to complete.
25
+
26
+ ## Security Rules — ABSOLUTE
27
+
28
+ ### Firmware Update Safety
29
+
30
+ - NEVER interrupt a firmware update in progress — this can BRICK the device.
31
+ - ALWAYS ensure the device has sufficient battery before starting (if applicable).
32
+ - ALWAYS confirm with the user before starting a firmware update:
33
+ "Firmware updates modify your device's system software. Do NOT disconnect
34
+ the device during the update. Continue?"
35
+ - After firmware update, the device may require re-entering the PIN.
36
+ - Firmware updates do NOT erase wallet data (seeds are preserved in the secure element).
37
+
38
+ ### Bootloader Safety
39
+
40
+ - If the device is in bootloader mode, only firmware update operations are available.
41
+ - NEVER attempt to exit bootloader mode during an active update.
42
+ - If the device is stuck in bootloader mode unexpectedly, guide the user to
43
+ contact OneKey support.
44
+
45
+ ## Commands
46
+
47
+ ### `onekey-hw firmware-check`
48
+
49
+ Check if a firmware update is available for the connected device.
50
+
51
+ ```bash
52
+ onekey-hw firmware-check [--connect-id <id>]
53
+ ```
54
+
55
+ **Agent notes:**
56
+ - Always check firmware before any operation to ensure compatibility.
57
+ - If `required` is true, the update is mandatory — signing may not work until updated.
58
+ - Present changelog to user so they can make an informed decision.
59
+
60
+ ### `onekey-hw firmware-check-all`
61
+
62
+ Check all firmware components at once (system, BLE, bootloader).
63
+
64
+ ```bash
65
+ onekey-hw firmware-check-all [--connect-id <id>]
66
+ ```
67
+
68
+ ### `onekey-hw firmware-update`
69
+
70
+ Update the device firmware (system firmware).
71
+
72
+ ```bash
73
+ onekey-hw firmware-update \
74
+ [--connect-id <id>] \
75
+ [--version <version>] \
76
+ [--platform <platform>]
77
+ ```
78
+
79
+ | Parameter | Required | Description |
80
+ |---|---|---|
81
+ | `--connect-id` | No | Device connection ID |
82
+ | `--version` | No | Target version, e.g. "4.8.0" (defaults to latest) |
83
+ | `--platform` | No | Platform: native, desktop, ext, web (default: desktop) |
84
+
85
+ **Agent notes:**
86
+ - This operation takes 1-3 minutes. Inform the user to be patient.
87
+ - The device will reboot during the update — this is normal.
88
+ - After update, run `onekey-hw search` again to re-detect the device.
89
+ - If the update fails, the device may enter bootloader mode — guide recovery.
90
+
91
+ ### `onekey-hw firmware-update-ble`
92
+
93
+ Update the BLE (Bluetooth) firmware.
94
+
95
+ ```bash
96
+ onekey-hw firmware-update-ble \
97
+ [--connect-id <id>] \
98
+ [--version <version>] \
99
+ [--platform <platform>]
100
+ ```
101
+
102
+ **Agent notes:**
103
+ - BLE update is separate from system firmware update.
104
+ - Only applicable for devices with Bluetooth capability (Touch, Pro).
105
+ - After BLE update, Bluetooth pairing may need to be re-established.
106
+
107
+ ### `onekey-hw bootloader-check`
108
+
109
+ Check bootloader version and status.
110
+
111
+ ```bash
112
+ onekey-hw bootloader-check [--connect-id <id>]
113
+ ```
114
+
115
+ ## Workflows
116
+
117
+ ### Check & Update Firmware
118
+
119
+ ```
120
+ User: "Is my firmware up to date?"
121
+
122
+ Step 1 — Check all components
123
+ → onekey-hw firmware-check-all --connect-id <id> --json
124
+ → Present results in a clear table
125
+
126
+ Step 2 — If updates available, ask user
127
+ → "BLE firmware v2.1.0 is available (current: v2.0.0). Changes: Improved BLE stability."
128
+ → "Would you like to update?"
129
+
130
+ Step 3 — User confirms → update
131
+ → "DO NOT disconnect your device during the update."
132
+ → onekey-hw firmware-update-ble --connect-id <id>
133
+ → "BLE firmware updated to v2.1.0."
134
+ ```
135
+
136
+ ### Recover from Bootloader Mode
137
+
138
+ ```
139
+ User: "My device shows a bootloader screen"
140
+
141
+ Step 1 — Verify bootloader mode
142
+ → onekey-hw status --connect-id <id>
143
+ → If bootloaderMode: true, proceed
144
+
145
+ Step 2 — Attempt firmware update to recover
146
+ → "Your device is in bootloader mode. This usually means a firmware update
147
+ was interrupted. Let's reinstall the firmware."
148
+ → onekey-hw firmware-update --connect-id <id>
149
+ → "Firmware installed. Your device should restart normally."
150
+ ```
151
+
152
+ ## When To Use
153
+
154
+ - User asks about firmware versions or updates.
155
+ - User wants to update device firmware.
156
+ - Device is in bootloader mode and needs recovery.
157
+ - Pre-check before signing to ensure firmware compatibility.
158
+
159
+ ## When NOT To Use
160
+
161
+ - User wants to sign transactions → use `hardware-signing`.
162
+ - User wants to connect devices → use `hardware-device`.
163
+ - User wants to change PIN/passphrase → use `hardware-security`.