@onekeyfe/hwk-adapter-core 1.1.26-alpha.100
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/dist/index.d.mts +1010 -0
- package/dist/index.d.ts +1010 -0
- package/dist/index.js +447 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +398 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
declare enum HardwareErrorCode {
|
|
2
|
+
UnknownError = 0,
|
|
3
|
+
DeviceNotFound = 1,
|
|
4
|
+
DeviceDisconnected = 2,
|
|
5
|
+
UserRejected = 3,
|
|
6
|
+
DeviceBusy = 4,
|
|
7
|
+
FirmwareUpdateRequired = 5,
|
|
8
|
+
AppNotOpen = 6,
|
|
9
|
+
InvalidParams = 7,
|
|
10
|
+
TransportError = 8,
|
|
11
|
+
OperationTimeout = 9,
|
|
12
|
+
MethodNotSupported = 10,
|
|
13
|
+
PinInvalid = 5520,
|
|
14
|
+
PinCancelled = 5521,
|
|
15
|
+
PassphraseRejected = 5522,
|
|
16
|
+
DeviceLocked = 5530,
|
|
17
|
+
DeviceNotInitialized = 5531,
|
|
18
|
+
DeviceInBootloader = 5532,
|
|
19
|
+
FirmwareTooOld = 5533,
|
|
20
|
+
WrongApp = 5540,
|
|
21
|
+
DeviceMismatch = 5560,
|
|
22
|
+
BridgeNotFound = 5550,
|
|
23
|
+
TransportNotAvailable = 5551
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Success<T> {
|
|
27
|
+
success: true;
|
|
28
|
+
payload: T;
|
|
29
|
+
}
|
|
30
|
+
interface Failure {
|
|
31
|
+
success: false;
|
|
32
|
+
payload: {
|
|
33
|
+
error: string;
|
|
34
|
+
code: HardwareErrorCode;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
type Response<T> = Success<T> | Failure;
|
|
38
|
+
declare function success<T>(payload: T): Success<T>;
|
|
39
|
+
declare function failure(code: HardwareErrorCode, error: string): Failure;
|
|
40
|
+
|
|
41
|
+
type VendorType = 'trezor' | 'ledger' | 'keystone' | 'keystoneqr';
|
|
42
|
+
type ConnectionType = 'usb' | 'ble' | 'qr';
|
|
43
|
+
type TransportType = 'usb' | 'ble' | 'hid' | 'bridge' | 'qr';
|
|
44
|
+
/**
|
|
45
|
+
* Device capabilities — describes what a specific device/connection
|
|
46
|
+
* combination can or cannot do. Varies by vendor, model, and connection type.
|
|
47
|
+
*
|
|
48
|
+
* This enables business logic to check capabilities instead of hard-coding
|
|
49
|
+
* vendor-specific conditions (e.g., `if (vendor === 'ledger')`).
|
|
50
|
+
*/
|
|
51
|
+
interface DeviceCapabilities {
|
|
52
|
+
/**
|
|
53
|
+
* Whether connectId/deviceId persist across sessions.
|
|
54
|
+
*
|
|
55
|
+
* - `true`: IDs are stable (e.g., OneKey USB, Trezor USB).
|
|
56
|
+
* Business logic can match devices by stored connectId/deviceId.
|
|
57
|
+
* - `false`: IDs are ephemeral, regenerated each session (e.g., Ledger WebHID).
|
|
58
|
+
* Business logic should NOT rely on stored connectId/deviceId for matching.
|
|
59
|
+
*/
|
|
60
|
+
persistentDeviceIdentity: boolean;
|
|
61
|
+
}
|
|
62
|
+
interface DeviceInfo {
|
|
63
|
+
vendor: VendorType;
|
|
64
|
+
model: string;
|
|
65
|
+
firmwareVersion: string;
|
|
66
|
+
deviceId: string;
|
|
67
|
+
connectId: string;
|
|
68
|
+
label?: string;
|
|
69
|
+
connectionType: ConnectionType;
|
|
70
|
+
battery?: number;
|
|
71
|
+
/** Device capabilities — varies by vendor, model, and connection type */
|
|
72
|
+
capabilities?: DeviceCapabilities;
|
|
73
|
+
}
|
|
74
|
+
interface DeviceTarget {
|
|
75
|
+
connectId: string;
|
|
76
|
+
deviceId: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface EvmGetAddressParams {
|
|
80
|
+
path: string;
|
|
81
|
+
showOnDevice?: boolean;
|
|
82
|
+
chainId?: number;
|
|
83
|
+
}
|
|
84
|
+
interface EvmAddress {
|
|
85
|
+
address: string;
|
|
86
|
+
path: string;
|
|
87
|
+
}
|
|
88
|
+
interface EvmGetPublicKeyParams {
|
|
89
|
+
path: string;
|
|
90
|
+
showOnDevice?: boolean;
|
|
91
|
+
}
|
|
92
|
+
interface EvmPublicKey {
|
|
93
|
+
publicKey: string;
|
|
94
|
+
path: string;
|
|
95
|
+
}
|
|
96
|
+
interface EvmSignTxParams {
|
|
97
|
+
path: string;
|
|
98
|
+
/**
|
|
99
|
+
* RLP-serialized transaction hex (0x-prefixed or plain).
|
|
100
|
+
* When provided, the connector uses this directly instead of individual fields.
|
|
101
|
+
* Required for Ledger; Trezor may use individual fields instead.
|
|
102
|
+
*/
|
|
103
|
+
serializedTx?: string;
|
|
104
|
+
/** Contract address or recipient. Optional for contract deployment transactions. */
|
|
105
|
+
to?: string;
|
|
106
|
+
value?: string;
|
|
107
|
+
chainId?: number;
|
|
108
|
+
nonce?: string;
|
|
109
|
+
gasLimit?: string;
|
|
110
|
+
gasPrice?: string;
|
|
111
|
+
maxFeePerGas?: string;
|
|
112
|
+
maxPriorityFeePerGas?: string;
|
|
113
|
+
accessList?: Array<{
|
|
114
|
+
address: string;
|
|
115
|
+
storageKeys: string[];
|
|
116
|
+
}>;
|
|
117
|
+
data?: string;
|
|
118
|
+
}
|
|
119
|
+
interface EvmSignedTx {
|
|
120
|
+
/** Recovery id as `0x`-prefixed hex string. */
|
|
121
|
+
v: string;
|
|
122
|
+
/** ECDSA `r` value as `0x`-prefixed, zero-padded 64-char hex string (32 bytes). */
|
|
123
|
+
r: string;
|
|
124
|
+
/** ECDSA `s` value as `0x`-prefixed, zero-padded 64-char hex string (32 bytes). */
|
|
125
|
+
s: string;
|
|
126
|
+
serializedTx?: string;
|
|
127
|
+
}
|
|
128
|
+
interface EvmSignMsgParams {
|
|
129
|
+
path: string;
|
|
130
|
+
message: string;
|
|
131
|
+
hex?: boolean;
|
|
132
|
+
}
|
|
133
|
+
type EvmSignTypedDataParams = EvmSignTypedDataFull | EvmSignTypedDataHash;
|
|
134
|
+
interface EvmSignTypedDataFull {
|
|
135
|
+
path: string;
|
|
136
|
+
/** Defaults to `'full'` when omitted. */
|
|
137
|
+
mode?: 'full';
|
|
138
|
+
data: {
|
|
139
|
+
domain: EIP712Domain;
|
|
140
|
+
types: Record<string, Array<{
|
|
141
|
+
name: string;
|
|
142
|
+
type: string;
|
|
143
|
+
}>>;
|
|
144
|
+
primaryType: string;
|
|
145
|
+
message: Record<string, unknown>;
|
|
146
|
+
};
|
|
147
|
+
metamaskV4Compat?: boolean;
|
|
148
|
+
}
|
|
149
|
+
interface EvmSignTypedDataHash {
|
|
150
|
+
path: string;
|
|
151
|
+
mode: 'hash';
|
|
152
|
+
domainSeparatorHash: string;
|
|
153
|
+
messageHash: string;
|
|
154
|
+
}
|
|
155
|
+
interface EIP712Domain {
|
|
156
|
+
name?: string;
|
|
157
|
+
version?: string;
|
|
158
|
+
chainId?: number;
|
|
159
|
+
verifyingContract?: string;
|
|
160
|
+
salt?: string;
|
|
161
|
+
[key: string]: unknown;
|
|
162
|
+
}
|
|
163
|
+
interface EvmSignature {
|
|
164
|
+
/** `0x`-prefixed hex string (r + s + v). */
|
|
165
|
+
signature: string;
|
|
166
|
+
address?: string;
|
|
167
|
+
}
|
|
168
|
+
type ProgressCallback = (progress: {
|
|
169
|
+
index: number;
|
|
170
|
+
total: number;
|
|
171
|
+
}) => void;
|
|
172
|
+
interface IEvmMethods {
|
|
173
|
+
evmGetAddress(connectId: string, deviceId: string, params: EvmGetAddressParams): Promise<Response<EvmAddress>>;
|
|
174
|
+
evmGetAddresses(connectId: string, deviceId: string, params: EvmGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<EvmAddress[]>>;
|
|
175
|
+
evmGetPublicKey(connectId: string, deviceId: string, params: EvmGetPublicKeyParams): Promise<Response<EvmPublicKey>>;
|
|
176
|
+
evmSignTransaction(connectId: string, deviceId: string, params: EvmSignTxParams): Promise<Response<EvmSignedTx>>;
|
|
177
|
+
evmSignMessage(connectId: string, deviceId: string, params: EvmSignMsgParams): Promise<Response<EvmSignature>>;
|
|
178
|
+
evmSignTypedData(connectId: string, deviceId: string, params: EvmSignTypedDataParams): Promise<Response<EvmSignature>>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface BtcGetAddressParams {
|
|
182
|
+
path: string;
|
|
183
|
+
coin?: string;
|
|
184
|
+
showOnDevice?: boolean;
|
|
185
|
+
scriptType?: 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr';
|
|
186
|
+
addressIndex?: number;
|
|
187
|
+
change?: boolean;
|
|
188
|
+
}
|
|
189
|
+
interface BtcAddress {
|
|
190
|
+
address: string;
|
|
191
|
+
path: string;
|
|
192
|
+
}
|
|
193
|
+
interface BtcGetPublicKeyParams {
|
|
194
|
+
path: string;
|
|
195
|
+
coin?: string;
|
|
196
|
+
showOnDevice?: boolean;
|
|
197
|
+
}
|
|
198
|
+
interface BtcPublicKey {
|
|
199
|
+
xpub: string;
|
|
200
|
+
publicKey: string;
|
|
201
|
+
/** Parent key fingerprint (BIP-32), not the master fingerprint. */
|
|
202
|
+
fingerprint: number;
|
|
203
|
+
chainCode: string;
|
|
204
|
+
path: string;
|
|
205
|
+
depth: number;
|
|
206
|
+
}
|
|
207
|
+
interface BtcSignTxParams {
|
|
208
|
+
psbt?: string;
|
|
209
|
+
inputs?: BtcTxInput[];
|
|
210
|
+
outputs?: BtcTxOutput[];
|
|
211
|
+
refTxs?: BtcRefTransaction[];
|
|
212
|
+
coin: string;
|
|
213
|
+
locktime?: number;
|
|
214
|
+
version?: number;
|
|
215
|
+
}
|
|
216
|
+
interface BtcTxInput {
|
|
217
|
+
path: string;
|
|
218
|
+
prevHash: string;
|
|
219
|
+
prevIndex: number;
|
|
220
|
+
amount: string;
|
|
221
|
+
scriptType?: 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr';
|
|
222
|
+
sequence?: number;
|
|
223
|
+
}
|
|
224
|
+
interface BtcTxOutput {
|
|
225
|
+
address?: string;
|
|
226
|
+
path?: string;
|
|
227
|
+
amount: string;
|
|
228
|
+
scriptType?: 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr';
|
|
229
|
+
}
|
|
230
|
+
interface BtcRefTransaction {
|
|
231
|
+
hash: string;
|
|
232
|
+
version: number;
|
|
233
|
+
inputs: Array<{
|
|
234
|
+
prevHash: string;
|
|
235
|
+
prevIndex: number;
|
|
236
|
+
script: string;
|
|
237
|
+
sequence: number;
|
|
238
|
+
}>;
|
|
239
|
+
outputs: Array<{
|
|
240
|
+
amount: string;
|
|
241
|
+
scriptPubKey: string;
|
|
242
|
+
}>;
|
|
243
|
+
locktime: number;
|
|
244
|
+
}
|
|
245
|
+
interface BtcSignedTx {
|
|
246
|
+
signatures: string[];
|
|
247
|
+
serializedTx: string;
|
|
248
|
+
txid?: string;
|
|
249
|
+
signedPsbt?: string;
|
|
250
|
+
}
|
|
251
|
+
interface BtcSignMsgParams {
|
|
252
|
+
path: string;
|
|
253
|
+
message: string;
|
|
254
|
+
coin?: string;
|
|
255
|
+
}
|
|
256
|
+
interface BtcSignature {
|
|
257
|
+
signature: string;
|
|
258
|
+
address: string;
|
|
259
|
+
}
|
|
260
|
+
interface IBtcMethods {
|
|
261
|
+
btcGetAddress(connectId: string, deviceId: string, params: BtcGetAddressParams): Promise<Response<BtcAddress>>;
|
|
262
|
+
btcGetAddresses(connectId: string, deviceId: string, params: BtcGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<BtcAddress[]>>;
|
|
263
|
+
btcGetPublicKey(connectId: string, deviceId: string, params: BtcGetPublicKeyParams): Promise<Response<BtcPublicKey>>;
|
|
264
|
+
btcSignTransaction(connectId: string, deviceId: string, params: BtcSignTxParams): Promise<Response<BtcSignedTx>>;
|
|
265
|
+
btcSignMessage(connectId: string, deviceId: string, params: BtcSignMsgParams): Promise<Response<BtcSignature>>;
|
|
266
|
+
btcGetMasterFingerprint(connectId: string, deviceId: string): Promise<Response<{
|
|
267
|
+
masterFingerprint: string;
|
|
268
|
+
}>>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface SolGetAddressParams {
|
|
272
|
+
path: string;
|
|
273
|
+
showOnDevice?: boolean;
|
|
274
|
+
}
|
|
275
|
+
interface SolAddress {
|
|
276
|
+
/** Base58-encoded Solana address */
|
|
277
|
+
address: string;
|
|
278
|
+
path: string;
|
|
279
|
+
}
|
|
280
|
+
interface SolGetPublicKeyParams {
|
|
281
|
+
path: string;
|
|
282
|
+
showOnDevice?: boolean;
|
|
283
|
+
}
|
|
284
|
+
interface SolPublicKey {
|
|
285
|
+
/** Base58-encoded Ed25519 public key (same as the Solana address) */
|
|
286
|
+
publicKey: string;
|
|
287
|
+
path: string;
|
|
288
|
+
}
|
|
289
|
+
interface SolSignTxParams {
|
|
290
|
+
path: string;
|
|
291
|
+
/** Hex-encoded serialized transaction bytes (no 0x prefix) */
|
|
292
|
+
serializedTx: string;
|
|
293
|
+
additionalInfo?: {
|
|
294
|
+
tokenAccountsInfos?: Array<{
|
|
295
|
+
baseAddress: string;
|
|
296
|
+
tokenProgram: string;
|
|
297
|
+
tokenMint: string;
|
|
298
|
+
tokenAccount: string;
|
|
299
|
+
}>;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
interface SolSignedTx {
|
|
303
|
+
/** Hex-encoded Ed25519 signature (no 0x prefix) */
|
|
304
|
+
signature: string;
|
|
305
|
+
}
|
|
306
|
+
interface SolSignMsgParams {
|
|
307
|
+
path: string;
|
|
308
|
+
/** Message bytes as hex string (no 0x prefix) */
|
|
309
|
+
message: string;
|
|
310
|
+
}
|
|
311
|
+
interface SolSignature {
|
|
312
|
+
/** Hex-encoded Ed25519 signature (no 0x prefix) */
|
|
313
|
+
signature: string;
|
|
314
|
+
}
|
|
315
|
+
interface ISolMethods {
|
|
316
|
+
solGetAddress(connectId: string, deviceId: string, params: SolGetAddressParams): Promise<Response<SolAddress>>;
|
|
317
|
+
solGetAddresses(connectId: string, deviceId: string, params: SolGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<SolAddress[]>>;
|
|
318
|
+
solGetPublicKey(connectId: string, deviceId: string, params: SolGetPublicKeyParams): Promise<Response<SolPublicKey>>;
|
|
319
|
+
solSignTransaction(connectId: string, deviceId: string, params: SolSignTxParams): Promise<Response<SolSignedTx>>;
|
|
320
|
+
solSignMessage(connectId: string, deviceId: string, params: SolSignMsgParams): Promise<Response<SolSignature>>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface TronGetAddressParams {
|
|
324
|
+
path: string;
|
|
325
|
+
showOnDevice?: boolean;
|
|
326
|
+
}
|
|
327
|
+
interface TronAddress {
|
|
328
|
+
/** Base58check-encoded TRON address (starts with 'T') */
|
|
329
|
+
address: string;
|
|
330
|
+
path: string;
|
|
331
|
+
}
|
|
332
|
+
interface TronSignTxParams {
|
|
333
|
+
path: string;
|
|
334
|
+
/** Protobuf-encoded raw transaction hex (no 0x prefix) */
|
|
335
|
+
rawTxHex: string;
|
|
336
|
+
}
|
|
337
|
+
interface TronSignedTx {
|
|
338
|
+
/** 65-byte hex-encoded signature (no 0x prefix) */
|
|
339
|
+
signature: string;
|
|
340
|
+
}
|
|
341
|
+
interface TronSignMsgParams {
|
|
342
|
+
path: string;
|
|
343
|
+
/** Message hex (no 0x prefix) */
|
|
344
|
+
message: string;
|
|
345
|
+
}
|
|
346
|
+
interface TronSignature {
|
|
347
|
+
/** 65-byte hex-encoded signature (no 0x prefix) */
|
|
348
|
+
signature: string;
|
|
349
|
+
}
|
|
350
|
+
interface ITronMethods {
|
|
351
|
+
tronGetAddress(connectId: string, deviceId: string, params: TronGetAddressParams): Promise<Response<TronAddress>>;
|
|
352
|
+
tronGetAddresses(connectId: string, deviceId: string, params: TronGetAddressParams[], onProgress?: ProgressCallback): Promise<Response<TronAddress[]>>;
|
|
353
|
+
tronSignTransaction(connectId: string, deviceId: string, params: TronSignTxParams): Promise<Response<TronSignedTx>>;
|
|
354
|
+
tronSignMessage(connectId: string, deviceId: string, params: TronSignMsgParams): Promise<Response<TronSignature>>;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
interface QrDisplayData {
|
|
358
|
+
urType: string;
|
|
359
|
+
urData: string;
|
|
360
|
+
animated: boolean;
|
|
361
|
+
}
|
|
362
|
+
interface QrResponseData {
|
|
363
|
+
urType: string;
|
|
364
|
+
urData: string;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Chain fingerprint utilities for device identity verification.
|
|
369
|
+
*
|
|
370
|
+
* Ledger devices have ephemeral IDs that change every session.
|
|
371
|
+
* To verify that the same seed/device is connected, we derive an address
|
|
372
|
+
* at a fixed path (account 0, index 0) and hash it into a stable "chain fingerprint".
|
|
373
|
+
*/
|
|
374
|
+
/**
|
|
375
|
+
* Fixed derivation paths used to generate chain fingerprints.
|
|
376
|
+
* Uses standard index 0 — Ledger firmware shows device confirmation for
|
|
377
|
+
* non-standard paths (e.g., index=100), which would interrupt wallet creation.
|
|
378
|
+
* The address is hashed into a 16-char fingerprint, not exposed directly.
|
|
379
|
+
* - EVM: cointype 60 (Ledger ETH App only supports 60)
|
|
380
|
+
* - BTC: cointype 1 (testnet)
|
|
381
|
+
* - SOL: cointype 501, standard 3-level hardened
|
|
382
|
+
*/
|
|
383
|
+
declare const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string>;
|
|
384
|
+
type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';
|
|
385
|
+
/**
|
|
386
|
+
* Hash an address string into a 16-character hex fingerprint.
|
|
387
|
+
*
|
|
388
|
+
* Uses a simple non-cryptographic hash (FNV-1a based) to avoid
|
|
389
|
+
* pulling in a SHA-256 dependency. This is NOT used for security —
|
|
390
|
+
* only for device identity matching.
|
|
391
|
+
*/
|
|
392
|
+
declare function deriveDeviceFingerprint(address: string): string;
|
|
393
|
+
|
|
394
|
+
declare const DEVICE_EVENT = "DEVICE_EVENT";
|
|
395
|
+
/** Events originating from the hardware device. */
|
|
396
|
+
declare const DEVICE: {
|
|
397
|
+
readonly CONNECT: "device-connect";
|
|
398
|
+
readonly DISCONNECT: "device-disconnect";
|
|
399
|
+
readonly CHANGED: "device-changed";
|
|
400
|
+
readonly ACQUIRE: "device-acquire";
|
|
401
|
+
readonly RELEASE: "device-release";
|
|
402
|
+
readonly FEATURES: "features";
|
|
403
|
+
readonly SUPPORT_FEATURES: "support_features";
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
declare const UI_EVENT = "UI_EVENT";
|
|
407
|
+
declare const UI_REQUEST: {
|
|
408
|
+
readonly REQUEST_PIN: "ui-request-pin";
|
|
409
|
+
readonly REQUEST_PASSPHRASE: "ui-request-passphrase";
|
|
410
|
+
readonly REQUEST_PASSPHRASE_ON_DEVICE: "ui-request-passphrase-on-device";
|
|
411
|
+
readonly REQUEST_BUTTON: "ui-request-button";
|
|
412
|
+
readonly REQUEST_QR_DISPLAY: "ui-request-qr-display";
|
|
413
|
+
readonly REQUEST_QR_SCAN: "ui-request-qr-scan";
|
|
414
|
+
readonly REQUEST_DEVICE_PERMISSION: "ui-request-device-permission";
|
|
415
|
+
readonly REQUEST_SELECT_DEVICE: "ui-request-select-device";
|
|
416
|
+
readonly REQUEST_DEVICE_CONNECT: "ui-request-device-connect";
|
|
417
|
+
readonly CLOSE_UI_WINDOW: "ui-close";
|
|
418
|
+
readonly DEVICE_PROGRESS: "ui-device_progress";
|
|
419
|
+
readonly FIRMWARE_PROGRESS: "ui-firmware-progress";
|
|
420
|
+
readonly FIRMWARE_TIP: "ui-firmware-tip";
|
|
421
|
+
};
|
|
422
|
+
declare const UI_RESPONSE: {
|
|
423
|
+
readonly RECEIVE_PIN: "receive-pin";
|
|
424
|
+
readonly RECEIVE_PASSPHRASE: "receive-passphrase";
|
|
425
|
+
readonly RECEIVE_PASSPHRASE_ON_DEVICE: "receive-passphrase-on-device";
|
|
426
|
+
readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
|
|
427
|
+
readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
|
|
428
|
+
readonly CANCEL: "cancel";
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/** Events generated by SDK internal detection (not from hardware directly). */
|
|
432
|
+
declare const SDK: {
|
|
433
|
+
readonly DEVICE_STUCK: "device-stuck";
|
|
434
|
+
readonly DEVICE_UNRESPONSIVE: "device-unresponsive";
|
|
435
|
+
readonly DEVICE_RECOVERED: "device-recovered";
|
|
436
|
+
readonly DEVICE_INTERACTION: "device-interaction";
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
type ChainCapability = 'evm' | 'btc' | 'sol' | 'tron';
|
|
440
|
+
interface PassphraseResponse {
|
|
441
|
+
passphrase: string;
|
|
442
|
+
/** If true, passphrase will be entered on the device. `passphrase` field is ignored. */
|
|
443
|
+
onDevice?: boolean;
|
|
444
|
+
}
|
|
445
|
+
type DeviceEvent = {
|
|
446
|
+
type: typeof DEVICE.CONNECT;
|
|
447
|
+
payload: DeviceInfo;
|
|
448
|
+
} | {
|
|
449
|
+
type: typeof DEVICE.DISCONNECT;
|
|
450
|
+
payload: {
|
|
451
|
+
connectId: string;
|
|
452
|
+
};
|
|
453
|
+
} | {
|
|
454
|
+
type: typeof DEVICE.CHANGED;
|
|
455
|
+
payload: DeviceInfo;
|
|
456
|
+
};
|
|
457
|
+
type UiRequestEvent = {
|
|
458
|
+
type: typeof UI_REQUEST.REQUEST_PIN;
|
|
459
|
+
payload: {
|
|
460
|
+
device: DeviceInfo;
|
|
461
|
+
};
|
|
462
|
+
} | {
|
|
463
|
+
type: typeof UI_REQUEST.REQUEST_PASSPHRASE;
|
|
464
|
+
payload: {
|
|
465
|
+
device: DeviceInfo;
|
|
466
|
+
};
|
|
467
|
+
} | {
|
|
468
|
+
type: typeof UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE;
|
|
469
|
+
payload: {
|
|
470
|
+
device: DeviceInfo;
|
|
471
|
+
};
|
|
472
|
+
} | {
|
|
473
|
+
type: typeof UI_REQUEST.REQUEST_BUTTON;
|
|
474
|
+
payload: {
|
|
475
|
+
device: DeviceInfo;
|
|
476
|
+
code?: string;
|
|
477
|
+
};
|
|
478
|
+
} | {
|
|
479
|
+
type: typeof UI_REQUEST.REQUEST_QR_DISPLAY;
|
|
480
|
+
payload: {
|
|
481
|
+
device: DeviceInfo;
|
|
482
|
+
data: QrDisplayData;
|
|
483
|
+
};
|
|
484
|
+
} | {
|
|
485
|
+
type: typeof UI_REQUEST.REQUEST_QR_SCAN;
|
|
486
|
+
payload: {
|
|
487
|
+
device: DeviceInfo;
|
|
488
|
+
};
|
|
489
|
+
} | {
|
|
490
|
+
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
491
|
+
payload: Record<string, never>;
|
|
492
|
+
} | {
|
|
493
|
+
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
494
|
+
payload: {
|
|
495
|
+
devices: DeviceInfo[];
|
|
496
|
+
};
|
|
497
|
+
} | {
|
|
498
|
+
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
499
|
+
payload: {
|
|
500
|
+
message: string;
|
|
501
|
+
retryCount: number;
|
|
502
|
+
maxRetries: number;
|
|
503
|
+
};
|
|
504
|
+
} | {
|
|
505
|
+
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
506
|
+
payload: Record<string, never>;
|
|
507
|
+
};
|
|
508
|
+
type SdkEvent = {
|
|
509
|
+
type: typeof SDK.DEVICE_INTERACTION;
|
|
510
|
+
payload: {
|
|
511
|
+
connectId: string;
|
|
512
|
+
action: string;
|
|
513
|
+
};
|
|
514
|
+
} | {
|
|
515
|
+
type: typeof SDK.DEVICE_STUCK;
|
|
516
|
+
payload: {
|
|
517
|
+
connectId: string;
|
|
518
|
+
};
|
|
519
|
+
} | {
|
|
520
|
+
type: typeof SDK.DEVICE_UNRESPONSIVE;
|
|
521
|
+
payload: {
|
|
522
|
+
connectId: string;
|
|
523
|
+
};
|
|
524
|
+
} | {
|
|
525
|
+
type: typeof SDK.DEVICE_RECOVERED;
|
|
526
|
+
payload: {
|
|
527
|
+
connectId: string;
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
type HardwareEvent = DeviceEvent | UiRequestEvent | SdkEvent;
|
|
531
|
+
type DeviceEventListener = (event: HardwareEvent) => void;
|
|
532
|
+
/**
|
|
533
|
+
* Type-safe event map for IHardwareWallet.on / .off.
|
|
534
|
+
*
|
|
535
|
+
* Each key is a concrete event string (e.g. DEVICE.CONNECT = 'device-connect'),
|
|
536
|
+
* and the value is the narrowed event object the listener will receive.
|
|
537
|
+
*/
|
|
538
|
+
interface HardwareEventMap {
|
|
539
|
+
[DEVICE.CONNECT]: {
|
|
540
|
+
type: typeof DEVICE.CONNECT;
|
|
541
|
+
payload: DeviceInfo;
|
|
542
|
+
};
|
|
543
|
+
[DEVICE.DISCONNECT]: {
|
|
544
|
+
type: typeof DEVICE.DISCONNECT;
|
|
545
|
+
payload: {
|
|
546
|
+
connectId: string;
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
[DEVICE.CHANGED]: {
|
|
550
|
+
type: typeof DEVICE.CHANGED;
|
|
551
|
+
payload: DeviceInfo;
|
|
552
|
+
};
|
|
553
|
+
[UI_REQUEST.REQUEST_PIN]: {
|
|
554
|
+
type: typeof UI_REQUEST.REQUEST_PIN;
|
|
555
|
+
payload: {
|
|
556
|
+
device: DeviceInfo;
|
|
557
|
+
};
|
|
558
|
+
};
|
|
559
|
+
[UI_REQUEST.REQUEST_PASSPHRASE]: {
|
|
560
|
+
type: typeof UI_REQUEST.REQUEST_PASSPHRASE;
|
|
561
|
+
payload: {
|
|
562
|
+
device: DeviceInfo;
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
[UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE]: {
|
|
566
|
+
type: typeof UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE;
|
|
567
|
+
payload: {
|
|
568
|
+
device: DeviceInfo;
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
[UI_REQUEST.REQUEST_BUTTON]: {
|
|
572
|
+
type: typeof UI_REQUEST.REQUEST_BUTTON;
|
|
573
|
+
payload: {
|
|
574
|
+
device: DeviceInfo;
|
|
575
|
+
code?: string;
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
[UI_REQUEST.REQUEST_QR_DISPLAY]: {
|
|
579
|
+
type: typeof UI_REQUEST.REQUEST_QR_DISPLAY;
|
|
580
|
+
payload: {
|
|
581
|
+
device: DeviceInfo;
|
|
582
|
+
data: QrDisplayData;
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
[UI_REQUEST.REQUEST_QR_SCAN]: {
|
|
586
|
+
type: typeof UI_REQUEST.REQUEST_QR_SCAN;
|
|
587
|
+
payload: {
|
|
588
|
+
device: DeviceInfo;
|
|
589
|
+
};
|
|
590
|
+
};
|
|
591
|
+
[UI_REQUEST.REQUEST_DEVICE_PERMISSION]: {
|
|
592
|
+
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
593
|
+
payload: Record<string, never>;
|
|
594
|
+
};
|
|
595
|
+
[UI_REQUEST.REQUEST_SELECT_DEVICE]: {
|
|
596
|
+
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
597
|
+
payload: {
|
|
598
|
+
devices: DeviceInfo[];
|
|
599
|
+
};
|
|
600
|
+
};
|
|
601
|
+
[UI_REQUEST.REQUEST_DEVICE_CONNECT]: {
|
|
602
|
+
type: typeof UI_REQUEST.REQUEST_DEVICE_CONNECT;
|
|
603
|
+
payload: {
|
|
604
|
+
message: string;
|
|
605
|
+
retryCount: number;
|
|
606
|
+
maxRetries: number;
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
[UI_REQUEST.CLOSE_UI_WINDOW]: {
|
|
610
|
+
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
611
|
+
payload: Record<string, never>;
|
|
612
|
+
};
|
|
613
|
+
[SDK.DEVICE_INTERACTION]: {
|
|
614
|
+
type: typeof SDK.DEVICE_INTERACTION;
|
|
615
|
+
payload: {
|
|
616
|
+
connectId: string;
|
|
617
|
+
action: string;
|
|
618
|
+
};
|
|
619
|
+
};
|
|
620
|
+
[SDK.DEVICE_STUCK]: {
|
|
621
|
+
type: typeof SDK.DEVICE_STUCK;
|
|
622
|
+
payload: {
|
|
623
|
+
connectId: string;
|
|
624
|
+
};
|
|
625
|
+
};
|
|
626
|
+
[SDK.DEVICE_UNRESPONSIVE]: {
|
|
627
|
+
type: typeof SDK.DEVICE_UNRESPONSIVE;
|
|
628
|
+
payload: {
|
|
629
|
+
connectId: string;
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
[SDK.DEVICE_RECOVERED]: {
|
|
633
|
+
type: typeof SDK.DEVICE_RECOVERED;
|
|
634
|
+
payload: {
|
|
635
|
+
connectId: string;
|
|
636
|
+
};
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* UI handler for interactive request-response flows.
|
|
641
|
+
* Adapters call these when they need user input (PIN, passphrase, QR scan).
|
|
642
|
+
* Pure notifications (button confirm, progress) go through events instead.
|
|
643
|
+
*/
|
|
644
|
+
interface IUiHandler {
|
|
645
|
+
onPinRequest(device: DeviceInfo): Promise<string>;
|
|
646
|
+
onPassphraseRequest(device: DeviceInfo): Promise<string | PassphraseResponse>;
|
|
647
|
+
onQrDisplay(device: DeviceInfo, data: QrDisplayData): Promise<QrResponseData>;
|
|
648
|
+
onSelectDevice(devices: DeviceInfo[]): Promise<string>;
|
|
649
|
+
/**
|
|
650
|
+
* Check if device access permission is already granted.
|
|
651
|
+
* Returns { granted, context? }.
|
|
652
|
+
* - granted: true → skip onDevicePermission
|
|
653
|
+
* - granted: false → adapter calls onDevicePermission with the context
|
|
654
|
+
* - context: consumer-defined data passed through to onDevicePermission
|
|
655
|
+
*
|
|
656
|
+
* When connectId/deviceId are undefined (searchDevices), check environment-level
|
|
657
|
+
* permissions (USB: any paired device exists; BLE: bluetooth on + location permission).
|
|
658
|
+
* When connectId/deviceId are provided (business methods), check device-level
|
|
659
|
+
* permissions (USB: target device authorized; BLE: bluetooth on + device connected).
|
|
660
|
+
*/
|
|
661
|
+
checkDevicePermission?(params: {
|
|
662
|
+
transportType: TransportType;
|
|
663
|
+
connectId?: string;
|
|
664
|
+
deviceId?: string;
|
|
665
|
+
}): Promise<{
|
|
666
|
+
granted: boolean;
|
|
667
|
+
context?: Record<string, unknown>;
|
|
668
|
+
}>;
|
|
669
|
+
/**
|
|
670
|
+
* Request device access permission from the user.
|
|
671
|
+
* Only called when checkDevicePermission returns granted: false (or is not set).
|
|
672
|
+
*
|
|
673
|
+
* The handler decides what to do based on transportType + context:
|
|
674
|
+
* - usb/hid: open pairing page or call requestWebUSBDevice
|
|
675
|
+
* - ble: enable bluetooth, request location permission, start scanning
|
|
676
|
+
*/
|
|
677
|
+
onDevicePermission(params: {
|
|
678
|
+
transportType: TransportType;
|
|
679
|
+
context?: Record<string, unknown>;
|
|
680
|
+
}): Promise<void>;
|
|
681
|
+
}
|
|
682
|
+
interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, ISolMethods, ITronMethods {
|
|
683
|
+
readonly vendor: string;
|
|
684
|
+
readonly activeTransport: TransportType | null;
|
|
685
|
+
init(config: TConfig): Promise<void>;
|
|
686
|
+
dispose(): Promise<void>;
|
|
687
|
+
getAvailableTransports(): TransportType[];
|
|
688
|
+
switchTransport(type: TransportType): Promise<void>;
|
|
689
|
+
searchDevices(): Promise<DeviceInfo[]>;
|
|
690
|
+
connectDevice(connectId: string): Promise<Response<string>>;
|
|
691
|
+
disconnectDevice(connectId: string): Promise<void>;
|
|
692
|
+
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
693
|
+
getSupportedChains(): ChainCapability[];
|
|
694
|
+
cancel(connectId: string): void;
|
|
695
|
+
/**
|
|
696
|
+
* Respond to a ui-request-device-connect event.
|
|
697
|
+
* Call with 'confirm' after the user connects/unlocks the device to retry,
|
|
698
|
+
* or 'cancel' to abort the operation.
|
|
699
|
+
*/
|
|
700
|
+
deviceConnectResponse(type: 'confirm' | 'cancel'): void;
|
|
701
|
+
/**
|
|
702
|
+
* Derive a chain-specific fingerprint for the connected device.
|
|
703
|
+
*
|
|
704
|
+
* For Ledger: derives an address at a fixed testnet path and hashes it.
|
|
705
|
+
* For Trezor: returns the hardware device_id from firmware features.
|
|
706
|
+
*
|
|
707
|
+
* Used to verify that the same seed/device is connected across sessions,
|
|
708
|
+
* especially for vendors with ephemeral connectId/deviceId.
|
|
709
|
+
*/
|
|
710
|
+
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
711
|
+
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
712
|
+
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
713
|
+
on(event: string, listener: DeviceEventListener): void;
|
|
714
|
+
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
715
|
+
off(event: string, listener: DeviceEventListener): void;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Low-level device descriptor from Transport layer.
|
|
720
|
+
* Represents a physical device detected by USB/BLE scanning.
|
|
721
|
+
*/
|
|
722
|
+
interface DeviceDescriptor {
|
|
723
|
+
/** Unique device path (USB serial number, BLE address, etc.) */
|
|
724
|
+
path: string;
|
|
725
|
+
/** USB product ID */
|
|
726
|
+
product?: number;
|
|
727
|
+
/** USB vendor ID */
|
|
728
|
+
vendor?: number;
|
|
729
|
+
/** Device type/model identifier */
|
|
730
|
+
type?: string;
|
|
731
|
+
/** BLE device name (e.g., "Nano X 123A") — contains stable 4-digit HEX suffix */
|
|
732
|
+
name?: string;
|
|
733
|
+
/** Transport identifier (e.g., 'WEB-HID', 'BLE') */
|
|
734
|
+
transport?: string;
|
|
735
|
+
}
|
|
736
|
+
interface DeviceConnectEvent {
|
|
737
|
+
type: 'device-connected';
|
|
738
|
+
descriptor: DeviceDescriptor;
|
|
739
|
+
}
|
|
740
|
+
interface DeviceDisconnectEvent {
|
|
741
|
+
type: 'device-disconnected';
|
|
742
|
+
descriptor: DeviceDescriptor;
|
|
743
|
+
}
|
|
744
|
+
type DeviceChangeEvent = DeviceConnectEvent | DeviceDisconnectEvent;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Per-device serial job queue with preemption support and stuck recovery.
|
|
748
|
+
* Ensures that only one operation runs at a time per device, with intelligent
|
|
749
|
+
* handling of conflicting operations.
|
|
750
|
+
*/
|
|
751
|
+
type Interruptibility = 'none' | 'safe' | 'confirm';
|
|
752
|
+
type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';
|
|
753
|
+
interface JobOptions {
|
|
754
|
+
interruptibility?: Interruptibility;
|
|
755
|
+
label?: string;
|
|
756
|
+
}
|
|
757
|
+
interface ActiveJobInfo {
|
|
758
|
+
label?: string;
|
|
759
|
+
interruptibility: Interruptibility;
|
|
760
|
+
startedAt: number;
|
|
761
|
+
}
|
|
762
|
+
interface PreemptionEvent {
|
|
763
|
+
deviceId: string;
|
|
764
|
+
currentJob: ActiveJobInfo;
|
|
765
|
+
newJob: {
|
|
766
|
+
label?: string;
|
|
767
|
+
interruptibility: Interruptibility;
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
declare class DeviceJobQueue {
|
|
771
|
+
private readonly _queues;
|
|
772
|
+
private readonly _active;
|
|
773
|
+
/**
|
|
774
|
+
* Called when a new job conflicts with an active 'confirm'-level job.
|
|
775
|
+
* UI should show a dialog and return the user's decision.
|
|
776
|
+
* If not set, defaults to 'wait' (queue behind current job).
|
|
777
|
+
*/
|
|
778
|
+
onPreemptionRequest?: (event: PreemptionEvent) => Promise<PreemptionDecision>;
|
|
779
|
+
/**
|
|
780
|
+
* Enqueue a job for a specific device.
|
|
781
|
+
* If a job is already running for this device, behavior depends on interruptibility:
|
|
782
|
+
* - 'none': new job queues silently (no preemption possible)
|
|
783
|
+
* - 'safe': current job is auto-cancelled, new job runs immediately after
|
|
784
|
+
* - 'confirm': onPreemptionRequest is called to ask user
|
|
785
|
+
*/
|
|
786
|
+
enqueue<T>(deviceId: string, job: (signal: AbortSignal) => Promise<T>, options?: JobOptions): Promise<T>;
|
|
787
|
+
/** Manually cancel the active job on a device. Returns false if job is non-interruptible. */
|
|
788
|
+
cancelActive(deviceId: string): boolean;
|
|
789
|
+
/** Force cancel regardless of interruptibility. Use for device stuck recovery. */
|
|
790
|
+
forceCancelActive(deviceId: string): boolean;
|
|
791
|
+
/** Get info about the currently active job for a device, or null if idle. */
|
|
792
|
+
getActiveJob(deviceId: string): ActiveJobInfo | null;
|
|
793
|
+
clear(): void;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Abstraction for UI communication during device interactions.
|
|
798
|
+
* Implementations handle different execution contexts:
|
|
799
|
+
* - DirectUiBridge: same-process event emitter (default)
|
|
800
|
+
* - IframeUiBridge: postMessage-based (future)
|
|
801
|
+
* - ExtensionUiBridge: chrome.runtime.sendMessage (future)
|
|
802
|
+
*/
|
|
803
|
+
interface IUiBridge {
|
|
804
|
+
/** Ask the user for PIN entry. Returns the PIN string. */
|
|
805
|
+
requestPin(device: DeviceInfo, signal?: AbortSignal): Promise<string>;
|
|
806
|
+
/** Ask the user for passphrase entry. Returns the passphrase string. */
|
|
807
|
+
requestPassphrase(device: DeviceInfo, signal?: AbortSignal): Promise<string>;
|
|
808
|
+
/** Notify the UI about a button press request on the device. */
|
|
809
|
+
notifyButton(device: DeviceInfo, code?: string): void;
|
|
810
|
+
/**
|
|
811
|
+
* Ask the user whether to preempt the current device operation.
|
|
812
|
+
* Only called for 'confirm'-level operations.
|
|
813
|
+
*/
|
|
814
|
+
requestPreemption(device: DeviceInfo, activeLabel: string, newLabel: string): Promise<PreemptionDecision>;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Minimal device info returned during discovery (searchDevices).
|
|
819
|
+
* At scan time, full DeviceInfo fields like firmwareVersion are not yet available.
|
|
820
|
+
*/
|
|
821
|
+
interface ConnectorDevice {
|
|
822
|
+
connectId: string;
|
|
823
|
+
deviceId: string;
|
|
824
|
+
name: string;
|
|
825
|
+
model?: string;
|
|
826
|
+
/** Device capabilities — available from scan time */
|
|
827
|
+
capabilities?: DeviceCapabilities;
|
|
828
|
+
}
|
|
829
|
+
interface ConnectorSession {
|
|
830
|
+
sessionId: string;
|
|
831
|
+
deviceInfo: DeviceInfo;
|
|
832
|
+
}
|
|
833
|
+
type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
|
|
834
|
+
/**
|
|
835
|
+
* Interaction event types emitted via 'ui-event'.
|
|
836
|
+
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
837
|
+
*/
|
|
838
|
+
declare enum EConnectorInteraction {
|
|
839
|
+
/** Device requires user to open a specific app */
|
|
840
|
+
ConfirmOpenApp = "confirm-open-app",
|
|
841
|
+
/** Device requires user to unlock */
|
|
842
|
+
UnlockDevice = "unlock-device",
|
|
843
|
+
/** Device needs user to confirm on device (sign, verify, etc.) */
|
|
844
|
+
ConfirmOnDevice = "confirm-on-device",
|
|
845
|
+
/** Previous interaction completed — clear UI prompt */
|
|
846
|
+
InteractionComplete = "interaction-complete"
|
|
847
|
+
}
|
|
848
|
+
type ConnectorUiEvent = {
|
|
849
|
+
type: EConnectorInteraction.ConfirmOpenApp;
|
|
850
|
+
payload: {
|
|
851
|
+
sessionId: string;
|
|
852
|
+
};
|
|
853
|
+
} | {
|
|
854
|
+
type: EConnectorInteraction.UnlockDevice;
|
|
855
|
+
payload: {
|
|
856
|
+
sessionId: string;
|
|
857
|
+
};
|
|
858
|
+
} | {
|
|
859
|
+
type: EConnectorInteraction.ConfirmOnDevice;
|
|
860
|
+
payload: {
|
|
861
|
+
sessionId: string;
|
|
862
|
+
};
|
|
863
|
+
} | {
|
|
864
|
+
type: EConnectorInteraction.InteractionComplete;
|
|
865
|
+
payload: {
|
|
866
|
+
sessionId: string;
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
interface ConnectorEventMap {
|
|
870
|
+
'device-connect': {
|
|
871
|
+
device: ConnectorDevice;
|
|
872
|
+
};
|
|
873
|
+
'device-disconnect': {
|
|
874
|
+
connectId: string;
|
|
875
|
+
};
|
|
876
|
+
'ui-request': {
|
|
877
|
+
type: string;
|
|
878
|
+
payload?: unknown;
|
|
879
|
+
};
|
|
880
|
+
'ui-event': ConnectorUiEvent;
|
|
881
|
+
}
|
|
882
|
+
interface IConnector {
|
|
883
|
+
searchDevices(): Promise<ConnectorDevice[]>;
|
|
884
|
+
connect(deviceId?: string): Promise<ConnectorSession>;
|
|
885
|
+
disconnect(sessionId: string): Promise<void>;
|
|
886
|
+
call(sessionId: string, method: string, params: unknown): Promise<unknown>;
|
|
887
|
+
cancel(sessionId: string): Promise<void>;
|
|
888
|
+
/** Send a UI response (e.g. PIN, passphrase) to the device. */
|
|
889
|
+
uiResponse(response: {
|
|
890
|
+
type: string;
|
|
891
|
+
payload: unknown;
|
|
892
|
+
}): void;
|
|
893
|
+
on<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
894
|
+
off<K extends ConnectorEventType>(event: K, handler: (data: ConnectorEventMap[K]) => void): void;
|
|
895
|
+
reset(): void;
|
|
896
|
+
}
|
|
897
|
+
interface IHardwareBridge {
|
|
898
|
+
searchDevices(params: {
|
|
899
|
+
vendor: VendorType;
|
|
900
|
+
}): Promise<ConnectorDevice[]>;
|
|
901
|
+
connect(params: {
|
|
902
|
+
vendor: VendorType;
|
|
903
|
+
deviceId?: string;
|
|
904
|
+
}): Promise<ConnectorSession>;
|
|
905
|
+
disconnect(params: {
|
|
906
|
+
vendor: VendorType;
|
|
907
|
+
sessionId: string;
|
|
908
|
+
}): Promise<void>;
|
|
909
|
+
call(params: {
|
|
910
|
+
vendor: VendorType;
|
|
911
|
+
sessionId: string;
|
|
912
|
+
method: string;
|
|
913
|
+
callParams: unknown;
|
|
914
|
+
}): Promise<unknown>;
|
|
915
|
+
cancel(params: {
|
|
916
|
+
vendor: VendorType;
|
|
917
|
+
sessionId: string;
|
|
918
|
+
}): Promise<void>;
|
|
919
|
+
uiResponse(params: {
|
|
920
|
+
vendor: VendorType;
|
|
921
|
+
response: {
|
|
922
|
+
type: string;
|
|
923
|
+
payload: unknown;
|
|
924
|
+
};
|
|
925
|
+
}): void;
|
|
926
|
+
reset(params: {
|
|
927
|
+
vendor: VendorType;
|
|
928
|
+
}): void;
|
|
929
|
+
/** Register an event handler for connector events forwarded across the bridge. */
|
|
930
|
+
onEvent(params: {
|
|
931
|
+
vendor: VendorType;
|
|
932
|
+
}, handler: (event: {
|
|
933
|
+
type: ConnectorEventType;
|
|
934
|
+
data: unknown;
|
|
935
|
+
}) => void): void;
|
|
936
|
+
/** Unregister a previously registered event handler. */
|
|
937
|
+
offEvent(params: {
|
|
938
|
+
vendor: VendorType;
|
|
939
|
+
}, handler: (event: {
|
|
940
|
+
type: ConnectorEventType;
|
|
941
|
+
data: unknown;
|
|
942
|
+
}) => void): void;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Adapt an IHardwareBridge (multi-vendor backend) into a single-vendor IConnector.
|
|
946
|
+
* Every IConnector method becomes a transparent forward to bridge.<method>({ vendor, ... }).
|
|
947
|
+
* Events are forwarded via bridge.onEvent / offEvent.
|
|
948
|
+
*
|
|
949
|
+
* Use this anywhere the actual hardware lives behind a process / context boundary
|
|
950
|
+
* (Electron main, extension background, native module, worker, iframe).
|
|
951
|
+
*/
|
|
952
|
+
declare function createBridgedConnector(vendor: VendorType, bridge: IHardwareBridge): IConnector;
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* Minimal typed event emitter using Map<string, Set<listener>>.
|
|
956
|
+
* Each adapter uses this for device events (connect, disconnect, pin, etc.).
|
|
957
|
+
*
|
|
958
|
+
* TMap is a record mapping event name strings to their payload types.
|
|
959
|
+
* Example:
|
|
960
|
+
* type MyEvents = { 'connect': { id: string }; 'disconnect': { id: string } };
|
|
961
|
+
* const emitter = new TypedEventEmitter<MyEvents>();
|
|
962
|
+
* emitter.on('connect', (data) => { data.id }); // data is { id: string }
|
|
963
|
+
*
|
|
964
|
+
* For backward compatibility, TMap defaults to Record<string, any> so that
|
|
965
|
+
* existing code using `new TypedEventEmitter<SomeUnionType>()` still compiles.
|
|
966
|
+
*/
|
|
967
|
+
declare class TypedEventEmitter<TMap extends Record<string, any> = Record<string, any>> {
|
|
968
|
+
private readonly _listeners;
|
|
969
|
+
on<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;
|
|
970
|
+
on(event: string, listener: (event: any) => void): void;
|
|
971
|
+
off<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;
|
|
972
|
+
off(event: string, listener: (event: any) => void): void;
|
|
973
|
+
emit<K extends keyof TMap & string>(event: K, data: TMap[K]): void;
|
|
974
|
+
emit(event: string, data: unknown): void;
|
|
975
|
+
removeAllListeners(): void;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Compare two semver strings (e.g. "2.1.0" vs "2.3.1").
|
|
980
|
+
* Returns -1 if a < b, 0 if equal, 1 if a > b.
|
|
981
|
+
*/
|
|
982
|
+
declare function compareSemver(a: string, b: string): number;
|
|
983
|
+
|
|
984
|
+
/** Ensure hex string has 0x prefix */
|
|
985
|
+
declare function ensure0x(hex: string): string;
|
|
986
|
+
/** Strip 0x prefix from hex string */
|
|
987
|
+
declare function stripHex(hex: string): string;
|
|
988
|
+
/** Pad hex to 64 chars (32 bytes) with 0x prefix */
|
|
989
|
+
declare function padHex64(hex: string): string;
|
|
990
|
+
/** Convert a hex string (with or without 0x prefix) to a Uint8Array. */
|
|
991
|
+
declare function hexToBytes(hex: string): Uint8Array;
|
|
992
|
+
/** Convert a Uint8Array to a hex string (no 0x prefix). */
|
|
993
|
+
declare function bytesToHex(bytes: Uint8Array): string;
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Enrich a hardware error message with actionable recovery hints.
|
|
997
|
+
* Shared across adapters (Ledger, Trezor, etc.).
|
|
998
|
+
*/
|
|
999
|
+
declare function enrichErrorMessage(code: HardwareErrorCode, originalMessage: string): string;
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* Generic batch call with progress reporting.
|
|
1003
|
+
* If any single call fails, returns the failure immediately.
|
|
1004
|
+
*/
|
|
1005
|
+
declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam) => Promise<Response<TResult>>, onProgress?: (progress: {
|
|
1006
|
+
index: number;
|
|
1007
|
+
total: number;
|
|
1008
|
+
}) => void): Promise<Response<TResult[]>>;
|
|
1009
|
+
|
|
1010
|
+
export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignTxParams, type BtcSignature, type BtcSignedTx, type BtcTxInput, type BtcTxOutput, CHAIN_FINGERPRINT_PATHS, type ChainCapability, type ChainForFingerprint, type ConnectionType, type ConnectorDevice, type ConnectorEventMap, type ConnectorEventType, type ConnectorSession, DEVICE, DEVICE_EVENT, type DeviceCapabilities, type DeviceChangeEvent, type DeviceConnectEvent, type DeviceDescriptor, type DeviceDisconnectEvent, type DeviceEvent, type DeviceEventListener, type DeviceInfo, DeviceJobQueue, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmGetPublicKeyParams, type EvmPublicKey, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type IUiBridge, type IUiHandler, type Interruptibility, type JobOptions, type PassphraseResponse, type PreemptionDecision, type PreemptionEvent, type ProgressCallback, type QrDisplayData, type QrResponseData, type Response, SDK, type SdkEvent, type SolAddress, type SolGetAddressParams, type SolGetPublicKeyParams, type SolPublicKey, type SolSignMsgParams, type SolSignTxParams, type SolSignature, type SolSignedTx, type Success, type TransportType, type TronAddress, type TronGetAddressParams, type TronSignMsgParams, type TronSignTxParams, type TronSignature, type TronSignedTx, TypedEventEmitter, UI_EVENT, UI_REQUEST, UI_RESPONSE, type UiRequestEvent, type VendorType, batchCall, bytesToHex, compareSemver, createBridgedConnector, deriveDeviceFingerprint, enrichErrorMessage, ensure0x, failure, hexToBytes, padHex64, stripHex, success };
|