@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.
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "onekey-hardware",
3
+ "description": "OneKey hardware wallet CLI skills for Claude Code — device management, multi-chain signing, firmware updates",
4
+ "version": "0.1.0",
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
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Chain Resolver — maps chain identifiers to the correct SDK API calls.
3
+ * Handles derivation path defaults and chain-specific parameter transformations.
4
+ *
5
+ * Reference: developer-portal docs at
6
+ * content/en/hardware-sdk/chains/<chain>/<method>.mdx
7
+ * content/en/hardware-sdk/core-api-guide.mdx (HD path section)
8
+ *
9
+ * Type definitions: packages/core/src/types/api/*.ts
10
+ */
11
+ import type { CoreApi } from '@onekeyfe/hd-core';
12
+ /**
13
+ * Common params passed to all SDK methods.
14
+ * Reference: packages/core/src/types/api/export.ts (CommonParams)
15
+ */
16
+ export interface CommonCLIParams {
17
+ connectId?: string;
18
+ deviceId?: string;
19
+ passphraseState?: string;
20
+ useEmptyPassphrase?: boolean;
21
+ }
22
+ export interface GetAddressParams extends CommonCLIParams {
23
+ chain: string;
24
+ path?: string;
25
+ showOnDevice?: boolean;
26
+ }
27
+ export declare function resolveGetAddress(sdk: CoreApi, params: GetAddressParams): Promise<{
28
+ success: boolean;
29
+ error: string;
30
+ chain: string;
31
+ path: string;
32
+ } | {
33
+ chain: string;
34
+ path: string;
35
+ success?: undefined;
36
+ error?: undefined;
37
+ }>;
38
+ export interface GetPublicKeyParams extends CommonCLIParams {
39
+ chain: string;
40
+ path?: string;
41
+ }
42
+ export declare function resolveGetPublicKey(sdk: CoreApi, params: GetPublicKeyParams): Promise<{
43
+ chain: string;
44
+ path: string;
45
+ }>;
46
+ export interface SignTransactionParams extends CommonCLIParams {
47
+ chain: string;
48
+ path?: string;
49
+ transaction: Record<string, unknown>;
50
+ }
51
+ export declare function resolveSignTransaction(sdk: CoreApi, params: SignTransactionParams): Promise<{
52
+ chain: string;
53
+ path: string;
54
+ }>;
55
+ export interface SignMessageParams extends CommonCLIParams {
56
+ chain: string;
57
+ path?: string;
58
+ message: string;
59
+ }
60
+ export declare function resolveSignMessage(sdk: CoreApi, params: SignMessageParams): Promise<{
61
+ chain: string;
62
+ path: string;
63
+ }>;
64
+ export interface BatchGetAddressParams extends CommonCLIParams {
65
+ bundle: Array<{
66
+ chain: string;
67
+ path?: string;
68
+ showOnDevice?: boolean;
69
+ }>;
70
+ }
71
+ export declare function resolveBatchGetAddress(sdk: CoreApi, params: BatchGetAddressParams): Promise<{
72
+ success: boolean;
73
+ addresses: Record<string, unknown>[];
74
+ }>;
package/dist/chains.js ADDED
@@ -0,0 +1,307 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Chain Resolver — maps chain identifiers to the correct SDK API calls.
5
+ * Handles derivation path defaults and chain-specific parameter transformations.
6
+ *
7
+ * Reference: developer-portal docs at
8
+ * content/en/hardware-sdk/chains/<chain>/<method>.mdx
9
+ * content/en/hardware-sdk/core-api-guide.mdx (HD path section)
10
+ *
11
+ * Type definitions: packages/core/src/types/api/*.ts
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.resolveBatchGetAddress = exports.resolveSignMessage = exports.resolveSignTransaction = exports.resolveGetPublicKey = exports.resolveGetAddress = void 0;
15
+ // Default BIP44 derivation paths per chain
16
+ // Sources: developer-portal core-api-guide.mdx + chain-specific docs
17
+ const DEFAULT_PATHS = {
18
+ evm: "m/44'/60'/0'/0/0",
19
+ btc: "m/84'/0'/0'/0/0",
20
+ sol: "m/44'/501'/0'/0'",
21
+ tron: "m/44'/195'/0'/0/0",
22
+ cosmos: "m/44'/118'/0'/0/0",
23
+ cardano: "m/1852'/1815'/0'/0/0",
24
+ polkadot: "m/44'/354'/0'/0'/0'",
25
+ aptos: "m/44'/637'/0'/0'/0'",
26
+ sui: "m/44'/784'/0'/0'/0'",
27
+ near: "m/44'/397'/0'",
28
+ xrp: "m/44'/144'/0'/0/0",
29
+ stellar: "m/44'/148'/0'",
30
+ ton: "m/44'/607'/0'",
31
+ nostr: "m/44'/1237'/0'/0/0",
32
+ filecoin: "m/44'/461'/0'/0/0",
33
+ kaspa: "m/44'/111111'/0'/0/0",
34
+ algo: "m/44'/283'/0'/0/0",
35
+ conflux: "m/44'/503'/0'/0/0",
36
+ nervos: "m/44'/309'/0'/0/0",
37
+ alephium: "m/44'/1234'/0'/0/0",
38
+ neo: "m/44'/888'/0'/0/0",
39
+ starcoin: "m/44'/101010'/0'/0'/0'",
40
+ nem: "m/44'/43'/0'/0'/0'",
41
+ dnx: "m/44'/29538'/0'/0'/0'",
42
+ scdo: "m/44'/541'/0'/0/0",
43
+ benfen: "m/44'/728'/0'/0'/0'",
44
+ nexa: "m/44'/29223'/0'/0/0",
45
+ };
46
+ // Chain name aliases for fuzzy matching
47
+ const CHAIN_ALIASES = {
48
+ ethereum: 'evm',
49
+ eth: 'evm',
50
+ bitcoin: 'btc',
51
+ solana: 'sol',
52
+ dot: 'polkadot',
53
+ ada: 'cardano',
54
+ atom: 'cosmos',
55
+ apt: 'aptos',
56
+ ripple: 'xrp',
57
+ xlm: 'stellar',
58
+ fil: 'filecoin',
59
+ ckb: 'nervos',
60
+ alph: 'alephium',
61
+ cfx: 'conflux',
62
+ stc: 'starcoin',
63
+ xem: 'nem',
64
+ bfc: 'benfen',
65
+ };
66
+ function resolveChain(chain) {
67
+ const normalized = chain.toLowerCase().trim();
68
+ return CHAIN_ALIASES[normalized] || normalized;
69
+ }
70
+ function getDefaultPath(chain) {
71
+ const resolved = resolveChain(chain);
72
+ const path = DEFAULT_PATHS[resolved];
73
+ if (!path) {
74
+ throw new Error(`Unsupported chain: ${chain}. Supported: ${Object.keys(DEFAULT_PATHS).join(', ')}`);
75
+ }
76
+ return path;
77
+ }
78
+ async function resolveGetAddress(sdk, params) {
79
+ const chain = resolveChain(params.chain);
80
+ const path = params.path || getDefaultPath(chain);
81
+ const showOnOneKey = params.showOnDevice ?? true;
82
+ const connectId = params.connectId || '';
83
+ const deviceId = params.deviceId || '';
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ const chainMethodMap = {
86
+ evm: () => sdk.evmGetAddress(connectId, deviceId, { path, showOnOneKey }),
87
+ btc: () => sdk.btcGetAddress(connectId, deviceId, { path, showOnOneKey, coin: 'btc' }),
88
+ sol: () => sdk.solGetAddress(connectId, deviceId, { path, showOnOneKey }),
89
+ tron: () => sdk.tronGetAddress(connectId, deviceId, { path, showOnOneKey }),
90
+ cosmos: () => sdk.cosmosGetAddress(connectId, deviceId, { path, showOnOneKey }),
91
+ // Cardano requires networkId, protocolMagic, derivationType
92
+ cardano: () => sdk.cardanoGetAddress(connectId, deviceId, {
93
+ addressParameters: { path, addressType: 0 },
94
+ networkId: 1,
95
+ protocolMagic: 764824073,
96
+ derivationType: 1,
97
+ showOnOneKey,
98
+ }),
99
+ // Polkadot requires network param
100
+ polkadot: () => sdk.polkadotGetAddress(connectId, deviceId, {
101
+ path,
102
+ prefix: 0,
103
+ network: 'polkadot',
104
+ showOnOneKey,
105
+ }),
106
+ aptos: () => sdk.aptosGetAddress(connectId, deviceId, { path, showOnOneKey }),
107
+ sui: () => sdk.suiGetAddress(connectId, deviceId, { path, showOnOneKey }),
108
+ near: () => sdk.nearGetAddress(connectId, deviceId, { path, showOnOneKey }),
109
+ xrp: () => sdk.xrpGetAddress(connectId, deviceId, { path, showOnOneKey }),
110
+ stellar: () => sdk.stellarGetAddress(connectId, deviceId, { path, showOnOneKey }),
111
+ ton: () => sdk.tonGetAddress(connectId, deviceId, { path, showOnOneKey }),
112
+ filecoin: () => sdk.filecoinGetAddress(connectId, deviceId, { path, showOnOneKey }),
113
+ kaspa: () => sdk.kaspaGetAddress(connectId, deviceId, { path, showOnOneKey, prefix: 'kaspa' }),
114
+ algo: () => sdk.algoGetAddress(connectId, deviceId, { path, showOnOneKey }),
115
+ conflux: () => sdk.confluxGetAddress(connectId, deviceId, { path, showOnOneKey }),
116
+ nervos: () => sdk.nervosGetAddress(connectId, deviceId, { path, showOnOneKey, network: 'ckb' }),
117
+ alephium: () => sdk.alephiumGetAddress(connectId, deviceId, { path, showOnOneKey, group: 0 }),
118
+ neo: () => sdk.neoGetAddress(connectId, deviceId, { path, showOnOneKey }),
119
+ starcoin: () => sdk.starcoinGetAddress(connectId, deviceId, { path, showOnOneKey }),
120
+ nem: () => sdk.nemGetAddress(connectId, deviceId, { path, showOnOneKey, network: 104 }),
121
+ dnx: () => sdk.dnxGetAddress(connectId, deviceId, { path, showOnOneKey }),
122
+ scdo: () => sdk.scdoGetAddress(connectId, deviceId, { path, showOnOneKey }),
123
+ benfen: () => sdk.benfenGetAddress(connectId, deviceId, { path, showOnOneKey }),
124
+ nexa: () => sdk.nexaGetAddress(connectId, deviceId, { path, showOnOneKey, prefix: 'nexa' }),
125
+ };
126
+ const method = chainMethodMap[chain];
127
+ if (!method) {
128
+ throw new Error(`getAddress not supported for chain: ${chain}`);
129
+ }
130
+ const result = await method();
131
+ if (result == null) {
132
+ return { success: false, error: 'No response from device', chain, path };
133
+ }
134
+ return { ...result, chain, path };
135
+ }
136
+ exports.resolveGetAddress = resolveGetAddress;
137
+ async function resolveGetPublicKey(sdk, params) {
138
+ const chain = resolveChain(params.chain);
139
+ const path = params.path || getDefaultPath(chain);
140
+ const connectId = params.connectId || '';
141
+ const deviceId = params.deviceId || '';
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ const chainMethodMap = {
144
+ evm: () => sdk.evmGetPublicKey(connectId, deviceId, { path }),
145
+ btc: () => sdk.btcGetPublicKey(connectId, deviceId, { path, coin: 'btc' }),
146
+ aptos: () => sdk.aptosGetPublicKey(connectId, deviceId, { path }),
147
+ cosmos: () => sdk.cosmosGetPublicKey(connectId, deviceId, { path }),
148
+ sui: () => sdk.suiGetPublicKey(connectId, deviceId, { path }),
149
+ starcoin: () => sdk.starcoinGetPublicKey(connectId, deviceId, { path }),
150
+ nostr: () => sdk.nostrGetPublicKey(connectId, deviceId, { path }),
151
+ benfen: () => sdk.benfenGetPublicKey(connectId, deviceId, { path }),
152
+ cardano: () => sdk.cardanoGetPublicKey(connectId, deviceId, { path, derivationType: 1 }),
153
+ };
154
+ const method = chainMethodMap[chain];
155
+ if (!method) {
156
+ throw new Error(`getPublicKey not supported for chain: ${chain}. Supported: ${Object.keys(chainMethodMap).join(', ')}`);
157
+ }
158
+ const result = await method();
159
+ return { ...result, chain, path };
160
+ }
161
+ exports.resolveGetPublicKey = resolveGetPublicKey;
162
+ async function resolveSignTransaction(sdk, params) {
163
+ const chain = resolveChain(params.chain);
164
+ const path = params.path || getDefaultPath(chain);
165
+ const connectId = params.connectId || '';
166
+ const deviceId = params.deviceId || '';
167
+ const tx = params.transaction;
168
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
+ const chainMethodMap = {
170
+ // EVM: chainId is inside the transaction object, not top-level
171
+ evm: () => sdk.evmSignTransaction(connectId, deviceId, { path, transaction: tx }),
172
+ // BTC: requires inputs/outputs/refTxs/coin format
173
+ btc: () => sdk.btcSignTransaction(connectId, deviceId, { coin: 'btc', ...tx }),
174
+ sol: () => sdk.solSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
175
+ tron: () => sdk.tronSignTransaction(connectId, deviceId, { path, transaction: tx }),
176
+ cosmos: () => sdk.cosmosSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
177
+ aptos: () => sdk.aptosSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
178
+ sui: () => sdk.suiSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
179
+ near: () => sdk.nearSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
180
+ // XRP: implementation reads path + transaction from payload despite type declaration
181
+ // eslint-disable-next-line @typescript-eslint/ban-types
182
+ xrp: () => sdk.xrpSignTransaction(connectId, deviceId, {
183
+ path,
184
+ transaction: tx,
185
+ }),
186
+ stellar: () => sdk.stellarSignTransaction(connectId, deviceId, {
187
+ path,
188
+ networkPassphrase: tx.networkPassphrase,
189
+ transaction: tx.transaction,
190
+ }),
191
+ // Polkadot: requires prefix param
192
+ polkadot: () => sdk.polkadotSignTransaction(connectId, deviceId, {
193
+ path,
194
+ rawTx: tx.rawTx,
195
+ network: tx.network || 'polkadot',
196
+ prefix: tx.prefix ?? 0,
197
+ }),
198
+ filecoin: () => sdk.filecoinSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
199
+ kaspa: () => sdk.kaspaSignTransaction(connectId, deviceId, { ...tx }),
200
+ algo: () => sdk.algoSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
201
+ conflux: () => sdk.confluxSignTransaction(connectId, deviceId, { path, transaction: tx }),
202
+ nervos: () => sdk.nervosSignTransaction(connectId, deviceId, { ...tx }),
203
+ alephium: () => sdk.alephiumSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
204
+ neo: () => sdk.neoSignTransaction(connectId, deviceId, { path, ...tx }),
205
+ dnx: () => sdk.dnxSignTransaction(connectId, deviceId, { path, ...tx }),
206
+ // SCDO: flat params (nonce, gasPrice, gasLimit, to, value, data), not wrapped
207
+ scdo: () => sdk.scdoSignTransaction(connectId, deviceId, { path, ...tx }),
208
+ benfen: () => sdk.benfenSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
209
+ nexa: () => sdk.nexaSignTransaction(connectId, deviceId, { ...tx }),
210
+ cardano: () => sdk.cardanoSignTransaction(connectId, deviceId, { ...tx }),
211
+ starcoin: () => sdk.starcoinSignTransaction(connectId, deviceId, { path, rawTx: tx.rawTx }),
212
+ };
213
+ const method = chainMethodMap[chain];
214
+ if (!method) {
215
+ throw new Error(`signTransaction not supported for chain: ${chain}`);
216
+ }
217
+ const result = await method();
218
+ return { ...result, chain, path };
219
+ }
220
+ exports.resolveSignTransaction = resolveSignTransaction;
221
+ async function resolveSignMessage(sdk, params) {
222
+ const chain = resolveChain(params.chain);
223
+ const path = params.path || getDefaultPath(chain);
224
+ const connectId = params.connectId || '';
225
+ const deviceId = params.deviceId || '';
226
+ // Most chains use `messageHex` (hex-encoded). CLI accepts either:
227
+ // - Already hex-encoded string (starts with "0x" or matches /^[0-9a-fA-F]+$/)
228
+ // - Plain text string (auto-converted to hex)
229
+ const raw = params.message;
230
+ const isHex = /^(0x)?[0-9a-fA-F]+$/.test(raw);
231
+ const msg = isHex ? raw.replace(/^0x/, '') : Buffer.from(raw, 'utf8').toString('hex');
232
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
+ const chainMethodMap = {
234
+ evm: () => sdk.evmSignMessage(connectId, deviceId, { path, messageHex: msg }),
235
+ // BTC: uses messageHex, not message
236
+ btc: () => sdk.btcSignMessage(connectId, deviceId, { path, messageHex: msg, coin: 'btc' }),
237
+ sol: () => sdk.solSignMessage(connectId, deviceId, { path, messageHex: msg }),
238
+ // Tron: uses messageHex
239
+ tron: () => sdk.tronSignMessage(connectId, deviceId, { path, messageHex: msg }),
240
+ aptos: () => sdk.aptosSignMessage(connectId, deviceId, { path, payload: { message: msg } }),
241
+ sui: () => sdk.suiSignMessage(connectId, deviceId, { path, messageHex: msg }),
242
+ // Conflux: uses messageHex
243
+ conflux: () => sdk.confluxSignMessage(connectId, deviceId, { path, messageHex: msg }),
244
+ // Starcoin: uses messageHex
245
+ starcoin: () => sdk.starcoinSignMessage(connectId, deviceId, { path, messageHex: msg }),
246
+ // TON: tonSignMessage is transfer-signing, pass JSON params
247
+ ton: () => {
248
+ const tonParams = JSON.parse(msg);
249
+ return sdk.tonSignMessage(connectId, deviceId, { path, ...tonParams });
250
+ },
251
+ // Nostr: event must be a NostrEvent object (kind, content, tags, created_at)
252
+ nostr: () => {
253
+ const event = JSON.parse(msg);
254
+ return sdk.nostrSignEvent(connectId, deviceId, { path, event });
255
+ },
256
+ // SCDO: uses messageHex
257
+ scdo: () => sdk.scdoSignMessage(connectId, deviceId, { path, messageHex: msg }),
258
+ // Alephium: requires messageType
259
+ alephium: () => sdk.alephiumSignMessage(connectId, deviceId, {
260
+ path,
261
+ messageHex: msg,
262
+ messageType: 'alephium',
263
+ }),
264
+ benfen: () => sdk.benfenSignMessage(connectId, deviceId, { path, messageHex: msg }),
265
+ // Cardano: uses `message` field, requires networkId
266
+ cardano: () => sdk.cardanoSignMessage(connectId, deviceId, {
267
+ path,
268
+ message: msg,
269
+ derivationType: 1,
270
+ networkId: 1,
271
+ }),
272
+ };
273
+ const method = chainMethodMap[chain];
274
+ if (!method) {
275
+ throw new Error(`signMessage not supported for chain: ${chain}. Supported: ${Object.keys(chainMethodMap).join(', ')}`);
276
+ }
277
+ const result = await method();
278
+ return { ...result, chain, path };
279
+ }
280
+ exports.resolveSignMessage = resolveSignMessage;
281
+ async function resolveBatchGetAddress(sdk, params) {
282
+ // #13 FIX: Collect per-item results with error handling for partial failures
283
+ const results = [];
284
+ for (const item of params.bundle) {
285
+ try {
286
+ const result = await resolveGetAddress(sdk, {
287
+ chain: item.chain,
288
+ path: item.path,
289
+ showOnDevice: item.showOnDevice ?? false,
290
+ connectId: params.connectId,
291
+ deviceId: params.deviceId,
292
+ });
293
+ results.push(result);
294
+ }
295
+ catch (err) {
296
+ results.push({
297
+ chain: item.chain,
298
+ path: item.path,
299
+ success: false,
300
+ error: err instanceof Error ? err.message : String(err),
301
+ });
302
+ }
303
+ }
304
+ const allSuccess = results.every(r => r.success !== false);
305
+ return { success: allSuccess, addresses: results };
306
+ }
307
+ exports.resolveBatchGetAddress = resolveBatchGetAddress;
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};