@onekeyfe/hardware-cli 1.1.26-alpha.106 → 1.1.26-alpha.4

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.
Files changed (41) hide show
  1. package/.eslintignore +4 -0
  2. package/dist/chains.d.ts +6 -0
  3. package/dist/chains.js +191 -87
  4. package/dist/cli.js +615 -496
  5. package/dist/index.d.ts +16 -89
  6. package/dist/index.js +1 -2
  7. package/dist/sdk.d.ts +15 -5
  8. package/dist/sdk.js +237 -131
  9. package/dist/session.d.ts +22 -0
  10. package/dist/session.js +83 -0
  11. package/dist/storage/index.d.ts +2 -0
  12. package/dist/storage/index.js +5 -0
  13. package/dist/storage/process-utils.d.ts +2 -0
  14. package/dist/storage/process-utils.js +44 -0
  15. package/dist/storage/secure-storage.linux.d.ts +11 -0
  16. package/dist/storage/secure-storage.linux.js +59 -0
  17. package/dist/storage/secure-storage.macos.d.ts +11 -0
  18. package/dist/storage/secure-storage.macos.js +65 -0
  19. package/dist/storage/storage-factory.d.ts +3 -0
  20. package/dist/storage/storage-factory.js +14 -0
  21. package/dist/storage/types.d.ts +18 -0
  22. package/dist/storage/types.js +2 -0
  23. package/package.json +15 -13
  24. package/src/chains.ts +229 -85
  25. package/src/cli.ts +620 -297
  26. package/src/sdk.ts +244 -125
  27. package/src/session.ts +89 -0
  28. package/src/storage/index.ts +2 -0
  29. package/src/storage/process-utils.ts +50 -0
  30. package/src/storage/secure-storage.linux.ts +68 -0
  31. package/src/storage/secure-storage.macos.ts +68 -0
  32. package/src/storage/storage-factory.ts +13 -0
  33. package/src/storage/types.ts +17 -0
  34. package/tsconfig.json +5 -7
  35. package/.claude-plugin/plugin.json +0 -14
  36. package/AGENTS.md +0 -40
  37. package/CLAUDE.md +0 -40
  38. package/README.md +0 -112
  39. package/evals/cases.json +0 -373
  40. package/evals/run-evals.sh +0 -136
  41. package/rollup.config.js +0 -28
@@ -0,0 +1,68 @@
1
+ import { defaultProcessRunner } from './process-utils';
2
+
3
+ import type { IProcessRunner, ISecureStorage, SecureStorageBackend } from './types';
4
+
5
+ const SERVICE_NAME = 'onekey-hw-cli';
6
+
7
+ export class MacOSSecureStorage implements ISecureStorage {
8
+ private readonly runner: IProcessRunner;
9
+
10
+ constructor(runner: IProcessRunner = defaultProcessRunner) {
11
+ this.runner = runner;
12
+ }
13
+
14
+ getBackendType(): SecureStorageBackend {
15
+ return 'macos-keychain';
16
+ }
17
+
18
+ async set(key: string, value: Buffer): Promise<void> {
19
+ const hex = value.toString('hex');
20
+ // Use `security -i` (interactive/batch mode): the tool parses commands
21
+ // from stdin internally instead of re-spawning a sub-process per command,
22
+ // so the password argument never appears in /proc or `ps aux` output.
23
+ //
24
+ // Keys are of the form `onekey-hw:<deviceId>/<slot>` and hex values only
25
+ // contain 0-9a-f, so neither contains shell metacharacters that would
26
+ // break the simple quoting security's parser expects.
27
+ const cmd = `add-generic-password -s "${SERVICE_NAME}" -a "${key}" -w "${hex}" -U`;
28
+ await this.runner.spawnWithStdin('security', ['-i'], cmd);
29
+ }
30
+
31
+ async get(key: string): Promise<Buffer | null> {
32
+ try {
33
+ const { stdout } = await this.runner.execFileAsync('security', [
34
+ 'find-generic-password',
35
+ '-s',
36
+ SERVICE_NAME,
37
+ '-a',
38
+ key,
39
+ '-w',
40
+ ]);
41
+ const hex = stdout.trim();
42
+ return hex ? Buffer.from(hex, 'hex') : null;
43
+ } catch (error) {
44
+ if (this.isItemNotFound(error)) return null;
45
+ throw error;
46
+ }
47
+ }
48
+
49
+ async delete(key: string): Promise<void> {
50
+ try {
51
+ await this.runner.execFileAsync('security', [
52
+ 'delete-generic-password',
53
+ '-s',
54
+ SERVICE_NAME,
55
+ '-a',
56
+ key,
57
+ ]);
58
+ } catch (error) {
59
+ if (this.isItemNotFound(error)) return;
60
+ throw error;
61
+ }
62
+ }
63
+
64
+ private isItemNotFound(error: unknown): boolean {
65
+ const err = error as Error & { code?: number; stderr?: string };
66
+ return err.code === 44 || err.stderr?.includes('could not be found') === true;
67
+ }
68
+ }
@@ -0,0 +1,13 @@
1
+ import { LinuxSecureStorage } from './secure-storage.linux';
2
+ import { MacOSSecureStorage } from './secure-storage.macos';
3
+
4
+ import type { ISecureStorage } from './types';
5
+
6
+ export function createSecureStorage(platform: NodeJS.Platform = process.platform): ISecureStorage {
7
+ if (platform === 'darwin') return new MacOSSecureStorage();
8
+ if (platform === 'linux') return new LinuxSecureStorage();
9
+ throw new Error(
10
+ `Secure storage is not supported on platform "${platform}". ` +
11
+ 'Use macOS Keychain or Linux Secret Service.'
12
+ );
13
+ }
@@ -0,0 +1,17 @@
1
+ export type SecureStorageBackend = 'macos-keychain' | 'linux-secret-service';
2
+
3
+ export interface ISecureStorage {
4
+ getBackendType(): SecureStorageBackend;
5
+ get(key: string): Promise<Buffer | null>;
6
+ set(key: string, value: Buffer): Promise<void>;
7
+ delete(key: string): Promise<void>;
8
+ }
9
+
10
+ export interface IProcessRunner {
11
+ execFileAsync(cmd: string, args: string[]): Promise<{ stdout: string; stderr: string }>;
12
+ spawnWithStdin(
13
+ cmd: string,
14
+ args: string[],
15
+ input: string
16
+ ): Promise<{ stdout: string; stderr: string }>;
17
+ }
package/tsconfig.json CHANGED
@@ -3,16 +3,14 @@
3
3
  "target": "ES2020",
4
4
  "module": "commonjs",
5
5
  "lib": ["ES2020"],
6
- "declaration": true,
6
+ "outDir": "dist",
7
+ "rootDir": "src",
7
8
  "strict": true,
8
- "noImplicitAny": false,
9
9
  "esModuleInterop": true,
10
10
  "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
11
  "resolveJsonModule": true,
13
- "outDir": "./dist",
14
- "rootDir": "./src"
12
+ "declaration": true
15
13
  },
16
- "include": ["src/**/*"],
17
- "exclude": ["node_modules", "dist", "evals"]
14
+ "include": ["src"],
15
+ "exclude": ["node_modules", "dist"]
18
16
  }
@@ -1,14 +0,0 @@
1
- {
2
- "name": "onekey-hardware",
3
- "description": "OneKey hardware wallet CLI skills for Claude Code — device management, multi-chain signing, firmware updates",
4
- "version": "1.1.25-alpha.1",
5
- "author": {
6
- "name": "OneKey",
7
- "email": "dev@onekey.so"
8
- },
9
- "homepage": "https://onekey.so",
10
- "repository": "https://github.com/OneKeyHQ/hardware-js-sdk",
11
- "license": "Apache-2.0",
12
- "keywords": ["hardware-wallet", "signing", "bitcoin", "ethereum", "onekey", "security"],
13
- "skills": "./skills/"
14
- }
package/AGENTS.md DELETED
@@ -1,40 +0,0 @@
1
- # OneKey Hardware Wallet — CLI Agent Skills
2
-
3
- When working with the `onekey-hw` CLI, read the skill files before running commands.
4
- Do NOT guess parameters or explore via `--help` — the skills document exact
5
- command signatures, workflows, and security rules.
6
-
7
- ## Skills
8
-
9
- | Skill | Path | Use When |
10
- |---|---|---|
11
- | **Device** | `skills/device/SKILL.md` | Search devices (with features), lock, verify, wipe |
12
- | **Signing** | `skills/signing/SKILL.md` | Get addresses, sign transactions/messages (27 chains) |
13
- | **Firmware** | `skills/firmware/SKILL.md` | Check firmware versions (updates via OneKey App only) |
14
- | **Security** | `skills/security/SKILL.md` | PIN, passphrase, device settings, factory reset |
15
-
16
- ## Quick Start
17
-
18
- ```bash
19
- # Install globally
20
- npm install -g @onekeyfe/hardware-cli
21
-
22
- # Search for connected devices (auto-fetches device info)
23
- onekey-hw search
24
-
25
- # Get an Ethereum address
26
- onekey-hw get-address --chain evm --use-empty-passphrase
27
-
28
- # Sign a message
29
- onekey-hw sign-message --chain evm --message "hello" --use-empty-passphrase
30
- ```
31
-
32
- ## Important
33
-
34
- - All signing operations require **physical confirmation** on the hardware device
35
- - Commands block while waiting for device interaction (PIN, button press)
36
- - All output is structured JSON
37
- - Uses direct USB (libusb) — no external daemon needed
38
-
39
- Each skill file includes pre-flight checks, security rules, and parameter
40
- conventions. Read the relevant skill for your task.
package/CLAUDE.md DELETED
@@ -1,40 +0,0 @@
1
- # OneKey Hardware Wallet — CLI Agent Skills
2
-
3
- When working with the `onekey-hw` CLI, read the skill files before running commands.
4
- Do NOT guess parameters or explore via `--help` — the skills document exact
5
- command signatures, workflows, and security rules.
6
-
7
- ## Skills
8
-
9
- | Skill | Path | Use When |
10
- |---|---|---|
11
- | **Device** | `skills/device/SKILL.md` | Search devices (with features), lock, verify, wipe |
12
- | **Signing** | `skills/signing/SKILL.md` | Get addresses, sign transactions/messages (27 chains) |
13
- | **Firmware** | `skills/firmware/SKILL.md` | Check firmware versions (updates via OneKey App only) |
14
- | **Security** | `skills/security/SKILL.md` | PIN, passphrase, device settings, factory reset |
15
-
16
- ## Quick Start
17
-
18
- ```bash
19
- # Install globally
20
- npm install -g @onekeyfe/hardware-cli
21
-
22
- # Search for connected devices (auto-fetches device info)
23
- onekey-hw search
24
-
25
- # Get an Ethereum address
26
- onekey-hw get-address --chain evm --use-empty-passphrase
27
-
28
- # Sign a message
29
- onekey-hw sign-message --chain evm --message "hello" --use-empty-passphrase
30
- ```
31
-
32
- ## Important
33
-
34
- - All signing operations require **physical confirmation** on the hardware device
35
- - Commands block while waiting for device interaction (PIN, button press)
36
- - All output is structured JSON
37
- - Uses direct USB (libusb) — no external daemon needed
38
-
39
- Each skill file includes pre-flight checks, security rules, and parameter
40
- conventions. Read the relevant skill for your task.
package/README.md DELETED
@@ -1,112 +0,0 @@
1
- # @onekeyfe/hardware-cli
2
-
3
- OneKey hardware wallet CLI for AI agent integration. Enables Claude Code and other AI agents to interact with OneKey hardware wallets — search devices, get addresses, sign transactions, manage firmware and security.
4
-
5
- ## Install
6
-
7
- ### Claude Code
8
-
9
- ```bash
10
- claude plugin marketplace add OneKeyHQ/hardware-js-sdk --sparse .claude-plugin packages/hd-cli
11
- claude plugin install onekey-hardware@onekey-hardware-plugins
12
- ```
13
-
14
- The CLI is installed automatically on first use via the skill's pre-flight check.
15
-
16
- ### Other AI Tools (Codex, Gemini, Cursor)
17
-
18
- ```bash
19
- npm install -g @onekeyfe/hardware-cli
20
- ```
21
-
22
- ### Development / Testing
23
-
24
- ```bash
25
- claude --plugin-dir /path/to/hardware-js-sdk/packages/hd-cli
26
- ```
27
-
28
- ## Commands
29
-
30
- ### Device
31
-
32
- | Command | Description | Needs PIN? |
33
- |---------|-------------|:----------:|
34
- | `onekey-hw search` | Search devices + auto-fetch features | No |
35
- | `onekey-hw lock` | Lock the device | No |
36
- | `onekey-hw device-verify` | Verify device is genuine | Yes |
37
- | `onekey-hw device-settings` | Update label, language, etc. | Yes |
38
- | `onekey-hw device-wipe` | Factory reset (IRREVERSIBLE) | Yes |
39
-
40
- ### Address & Signing
41
-
42
- | Command | Description | Needs PIN? |
43
- |---------|-------------|:----------:|
44
- | `onekey-hw get-address --chain <chain>` | Get address (27 chains) | Yes |
45
- | `onekey-hw get-public-key --chain <chain>` | Get public key | Yes |
46
- | `onekey-hw batch-get-address --bundle <json>` | Multi-chain batch | Yes |
47
- | `onekey-hw sign-transaction --chain <chain> --tx <json>` | Sign transaction | Yes |
48
- | `onekey-hw sign-message --chain <chain> --message <msg>` | Sign message | Yes |
49
- | `onekey-hw sign-typed-data --data <json>` | Sign EIP-712 (EVM) | Yes |
50
- | `onekey-hw sign-psbt --psbt <hex>` | Sign Bitcoin PSBT | Yes |
51
- | `onekey-hw verify-message --chain <chain> ...` | Verify signed message | Yes |
52
-
53
- ### Chain-Specific
54
-
55
- | Command | Description |
56
- |---------|-------------|
57
- | `onekey-hw evm-sign-eip712` | EIP-712 by hash |
58
- | `onekey-hw sol-sign-offchain` | Solana off-chain message |
59
- | `onekey-hw nostr-encrypt` | Nostr NIP-04 encrypt |
60
- | `onekey-hw nostr-decrypt` | Nostr NIP-04 decrypt |
61
- | `onekey-hw nostr-sign-schnorr` | Nostr Schnorr signature |
62
- | `onekey-hw lnurl-auth` | Lightning LNURL auth |
63
- | `onekey-hw conflux-sign-cip23` | Conflux CIP-23 message |
64
- | `onekey-hw aptos-sign-in` | Aptos sign-in |
65
- | `onekey-hw ton-sign-proof` | TON Connect proof |
66
-
67
- ### Firmware (Read-Only)
68
-
69
- | Command | Description |
70
- |---------|-------------|
71
- | `onekey-hw firmware-check` | Check firmware updates |
72
- | `onekey-hw firmware-check-all` | Check all components |
73
- | `onekey-hw bootloader-check` | Check bootloader |
74
-
75
- Firmware updates must be done via the [OneKey App](https://onekey.so/download) or [firmware.onekey.so](https://firmware.onekey.so/).
76
-
77
- ### Security
78
-
79
- | Command | Description |
80
- |---------|-------------|
81
- | `onekey-hw change-pin` | Change/set PIN |
82
- | `onekey-hw passphrase-state` | Get passphrase state |
83
- | `onekey-hw toggle-passphrase --enable <bool>` | Enable/disable passphrase |
84
-
85
- ## Supported Chains
86
-
87
- | Chain | `--chain` | Address | Sign TX | Sign Message |
88
- |-------|-----------|:-------:|:-------:|:------------:|
89
- | Ethereum / EVM | `evm` | ✅ | ✅ | ✅ |
90
- | Bitcoin | `btc` | ✅ | ✅ | ✅ |
91
- | Solana | `sol` | ✅ | ✅ | ✅ |
92
- | Cosmos | `cosmos` | ✅ | ✅ | — |
93
- | Cardano | `cardano` | ✅ | ✅ | ✅ |
94
- | Polkadot | `polkadot` | ✅ | ✅ | — |
95
- | Tron | `tron` | ✅ | ✅ | ✅ |
96
- | Aptos | `aptos` | ✅ | ✅ | ✅ |
97
- | Sui | `sui` | ✅ | ✅ | ✅ |
98
- | Near | `near` | ✅ | ✅ | — |
99
- | XRP | `xrp` | ✅ | ✅ | — |
100
- | Stellar | `stellar` | ✅ | ✅ | — |
101
- | TON | `ton` | ✅ | — | ✅ |
102
- | Nostr | `nostr` | ✅ | — | ✅ |
103
- | +13 more | | ✅ | ✅ | varies |
104
-
105
- ## Transport
106
-
107
- Uses `libusb` for direct USB communication. No external daemon needed.
108
- Works on macOS, Linux, and Windows.
109
-
110
- ## License
111
-
112
- Apache-2.0