@onekeyfe/hwk-keystone-adapter 1.2.6-alpha.0 → 1.2.8-alpha.13
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 +72 -36
- package/dist/index.d.ts +72 -36
- package/dist/index.js +653 -590
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +711 -642
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainCapability, DeviceInfo, IHardwareWallet, IConnector, TransportType, SearchDevicesOptions, DeviceSearchTarget,
|
|
1
|
+
import { ChainCapability, DeviceInfo, IHardwareWallet, IConnector, TransportType, SearchDevicesOptions, DeviceSearchTarget, Response, ChainForFingerprint, UiResponseEvent, HardwareEventMap, DeviceEventListener, AllNetworkGetAddressParams, AllNetworkAddressResponse, NullableCallArg, IHardwareCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, IHardwareCommonCallParams, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature } from '@onekeyfe/hwk-adapter-core';
|
|
2
2
|
|
|
3
3
|
/** Keystone `DataType`: 1 = transaction, 2 = personal message. */
|
|
4
4
|
declare enum TronSignType {
|
|
@@ -59,7 +59,7 @@ interface KeystoneBtcSignRequestAccount {
|
|
|
59
59
|
xfp: string;
|
|
60
60
|
address?: string;
|
|
61
61
|
}
|
|
62
|
-
/** Script types for purposes 44'/49'/84'/86'
|
|
62
|
+
/** Script types for purposes 44'/49'/84'/86'. */
|
|
63
63
|
type BtcScriptType = 'p2pkh' | 'p2sh-p2wpkh' | 'p2wpkh' | 'p2tr';
|
|
64
64
|
interface KeystoneSolSignRequestInput {
|
|
65
65
|
requestId: string;
|
|
@@ -134,15 +134,16 @@ declare class KeystoneUrEngine {
|
|
|
134
134
|
parseEthSignature(ur: KeystoneUr): KeystoneEthSignatureResult;
|
|
135
135
|
/** Derives an EVM address offline; `relativeDerivePath` is relative to the xpub, e.g. `'0/0'`. */
|
|
136
136
|
deriveEvmAddressFromXpub(xpub: string, relativeDerivePath: string): string;
|
|
137
|
-
/**
|
|
138
|
-
* `CryptoHDKey` always emits mainnet xpub version bytes (`0488B21E`), so `hdkey` parses it as is.
|
|
139
|
-
* `p2tr` needs an ECC lib for BIP-341 tweaking, not wired here.
|
|
140
|
-
*/
|
|
137
|
+
/** `CryptoHDKey` always emits mainnet xpub version bytes (`0488B21E`), so `hdkey` parses it as is. */
|
|
141
138
|
deriveBtcAddressFromXpub(xpub: string, relativeDerivePath: string, scriptType: BtcScriptType): string;
|
|
142
139
|
deriveBtcAddressFromPublicKey(publicKeyHex: string, scriptType: BtcScriptType): string;
|
|
143
140
|
buildBtcPsbtRequest(unsignedPsbtHex: string): KeystoneUr;
|
|
144
|
-
/**
|
|
145
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Returns the hex-encoded (possibly still-unsigned-in-part) PSBT the device replied with. A PSBT
|
|
143
|
+
* carries no request id, so the reply is bound to the request by its unsigned transaction, which
|
|
144
|
+
* signing never changes (BIP-174); a scan of another PSBT's signature is refused.
|
|
145
|
+
*/
|
|
146
|
+
parseBtcPsbt(ur: KeystoneUr, requestPsbtHex: string): string;
|
|
146
147
|
buildBtcMessageSignRequest(params: {
|
|
147
148
|
requestId: string;
|
|
148
149
|
/** Hex, no 0x prefix. */
|
|
@@ -206,8 +207,17 @@ declare function toDeviceInfo(record: KeystoneDeviceRecord): DeviceInfo;
|
|
|
206
207
|
/** Device row for a not-yet-synced wallet during a cold-start round trip. */
|
|
207
208
|
declare function placeholderDeviceInfo(): DeviceInfo;
|
|
208
209
|
|
|
209
|
-
/**
|
|
210
|
-
|
|
210
|
+
/**
|
|
211
|
+
* How an all-network item reads its key. QR: from the bundle's one scan, never the device again.
|
|
212
|
+
* USB: straight from the device, on the session the bundle started with.
|
|
213
|
+
*/
|
|
214
|
+
type BundleAccess = {
|
|
215
|
+
channel: 'qr';
|
|
216
|
+
scanned: ReadonlyMap<string, KeystoneAccountEntry>;
|
|
217
|
+
} | {
|
|
218
|
+
channel: 'usb';
|
|
219
|
+
usbSessionId: string;
|
|
220
|
+
};
|
|
211
221
|
interface ImportFromQrOptions {
|
|
212
222
|
/**
|
|
213
223
|
* 'request' asks the device for one account; 'scan' waits for whatever export it already shows.
|
|
@@ -267,7 +277,6 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
267
277
|
/** Best-effort disconnect; the session is retired either way so it cannot be selected again. */
|
|
268
278
|
private _retireUsbSession;
|
|
269
279
|
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
270
|
-
listConnectionTargets(options?: SearchDevicesOptions): Promise<ConnectionTarget[]>;
|
|
271
280
|
connectDevice(searchTargetId: string): Promise<Response<string>>;
|
|
272
281
|
/**
|
|
273
282
|
* QR has nothing to tear down. A USB session is closed, and the record is demoted to QR-only or
|
|
@@ -277,6 +286,10 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
277
286
|
private _releaseOperationConnection;
|
|
278
287
|
getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
279
288
|
cancel(connectId?: string): void;
|
|
289
|
+
/**
|
|
290
|
+
* Derived from the wallet's master fingerprint, which the caller already holds as deviceId; the
|
|
291
|
+
* device is never asked. It names the wallet but cannot check which device is attached.
|
|
292
|
+
*/
|
|
280
293
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
281
294
|
uiResponse(response: UiResponseEvent): void;
|
|
282
295
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -284,31 +297,46 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
284
297
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
285
298
|
off(event: string, listener: DeviceEventListener): void;
|
|
286
299
|
importFromQr(options?: ImportFromQrOptions): Promise<Response<DeviceInfo>>;
|
|
300
|
+
private _importFromQr;
|
|
287
301
|
allNetworkGetAddress: (connectId: string, deviceId: string, params: AllNetworkGetAddressParams) => Promise<Response<AllNetworkAddressResponse[]>>;
|
|
288
|
-
evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
289
|
-
evmSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
290
|
-
evmSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
291
|
-
evmSignTypedData(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
292
|
-
btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
302
|
+
evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmGetAddressParams>>, bundle?: BundleAccess): Promise<Response<EvmAddress>>;
|
|
303
|
+
evmSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmSignTxParams>>): Promise<Response<EvmSignedTx>>;
|
|
304
|
+
evmSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmSignMsgParams>>): Promise<Response<EvmSignature>>;
|
|
305
|
+
evmSignTypedData(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmSignTypedDataParams>>): Promise<Response<EvmSignature>>;
|
|
306
|
+
btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcGetAddressParams>>, bundle?: BundleAccess): Promise<Response<BtcAddress>>;
|
|
293
307
|
/**
|
|
294
308
|
* `params.path` must be an account path (`m/84'/0'/0'`), the level Keystone syncs. An xpub is
|
|
295
309
|
* script-type agnostic, so `86'` works here even though `btcGetAddress` rejects it.
|
|
296
310
|
*/
|
|
297
|
-
btcGetPublicKey(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
311
|
+
btcGetPublicKey(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcGetPublicKeyParams>>, bundle?: BundleAccess): Promise<Response<BtcPublicKey>>;
|
|
298
312
|
btcSignTransaction(_connectId?: NullableCallArg<string>, _deviceId?: NullableCallArg<string>, _params?: NullableCallArg<IHardwareCallParams<BtcSignTxParams>>): Promise<Response<BtcSignedTx>>;
|
|
299
|
-
btcSignPsbt(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
300
|
-
btcSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
313
|
+
btcSignPsbt(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcSignPsbtParams>>): Promise<Response<BtcSignedPsbt>>;
|
|
314
|
+
btcSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcSignMsgParams>>): Promise<Response<BtcSignature>>;
|
|
315
|
+
/**
|
|
316
|
+
* Returns the known master fingerprint for the named wallet without asking the device (a QR
|
|
317
|
+
* round trip only to repeat it would cost a scan). Use it to name the wallet, for example as a
|
|
318
|
+
* PSBT xfp, which the device itself checks when signing; it cannot check the attached device.
|
|
319
|
+
*/
|
|
301
320
|
btcGetMasterFingerprint(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCommonCallParams>): Promise<Response<{
|
|
302
321
|
masterFingerprint: string;
|
|
303
322
|
}>>;
|
|
304
|
-
solGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
305
|
-
solSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
306
|
-
solSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
307
|
-
tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
308
|
-
tronSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
309
|
-
tronSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
323
|
+
solGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<SolGetAddressParams>>, bundle?: BundleAccess): Promise<Response<SolAddress>>;
|
|
324
|
+
solSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<SolSignTxParams>>): Promise<Response<SolSignedTx>>;
|
|
325
|
+
solSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<SolSignMsgParams>>): Promise<Response<SolSignature>>;
|
|
326
|
+
tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<TronGetAddressParams>>, bundle?: BundleAccess): Promise<Response<TronAddress>>;
|
|
327
|
+
tronSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<TronSignTxParams>>): Promise<Response<TronSignedTx>>;
|
|
328
|
+
tronSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<TronSignMsgParams>>): Promise<Response<TronSignature>>;
|
|
329
|
+
/** Resolves the call's target and requires params, before any method-specific check. */
|
|
330
|
+
private _beginCall;
|
|
331
|
+
/** Derives a leaf address offline from its account xpub. */
|
|
332
|
+
private _addressFromAccountXpub;
|
|
333
|
+
private _evmSign;
|
|
334
|
+
private _solSign;
|
|
335
|
+
private _tronSign;
|
|
310
336
|
private _runJob;
|
|
311
337
|
private _fetchAccountXpub;
|
|
338
|
+
/** The exported key behind an address, reduced to the fields that identify it. */
|
|
339
|
+
private _exportedAccountKey;
|
|
312
340
|
/**
|
|
313
341
|
* Signing needs only the wallet's mfp: the device re-derives the key from path+xfp, so no
|
|
314
342
|
* per-path account lookup happens here.
|
|
@@ -316,11 +344,16 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
316
344
|
private _signWithWallet;
|
|
317
345
|
private _allNetworkSyncSchema;
|
|
318
346
|
/**
|
|
319
|
-
* QR answers
|
|
320
|
-
*
|
|
347
|
+
* Picks the bundle's channel. QR answers every item with one request QR and one scan; USB items
|
|
348
|
+
* each ask the device directly, like other vendors, on the session found here.
|
|
349
|
+
*/
|
|
350
|
+
private _prepareAllNetworkBundle;
|
|
351
|
+
/**
|
|
352
|
+
* A positional wallet id and an operation id must name the same wallet: otherwise the call
|
|
353
|
+
* would run on the operation's wallet while the caller files the result under the other one.
|
|
354
|
+
* Ids that do not carry a master fingerprint cannot be compared and pass through.
|
|
321
355
|
*/
|
|
322
|
-
private
|
|
323
|
-
/** Resolve the wallet's master fingerprint from the connectId and/or deviceId the caller passed. */
|
|
356
|
+
private _resolveOperationTarget;
|
|
324
357
|
private _resolveTarget;
|
|
325
358
|
private _assertParsedIdentity;
|
|
326
359
|
/**
|
|
@@ -340,16 +373,17 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
340
373
|
*/
|
|
341
374
|
private _tryUsbAttach;
|
|
342
375
|
/**
|
|
343
|
-
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session
|
|
344
|
-
* otherwise a failed USB reattach leaves the call on QR.
|
|
376
|
+
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
|
|
377
|
+
* and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
|
|
345
378
|
*/
|
|
346
379
|
private _resolveUr;
|
|
347
380
|
private _resolveUrWithRoute;
|
|
348
381
|
/** Ends the operation as disconnected and returns the error to throw. */
|
|
349
382
|
private _endDisconnectedOperation;
|
|
350
383
|
/**
|
|
351
|
-
* Fetches one account's key material
|
|
352
|
-
* failed USB export ends the operation
|
|
384
|
+
* Fetches one account's key material. An all-network QR item takes it from the bundle's scan; a
|
|
385
|
+
* USB item asks the device on the bundle's session. A failed USB export ends the operation
|
|
386
|
+
* without replaying or switching transports.
|
|
353
387
|
*/
|
|
354
388
|
private _fetchAccount;
|
|
355
389
|
/**
|
|
@@ -369,13 +403,15 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
369
403
|
* a cancel reach the wait before the QR timeout.
|
|
370
404
|
*/
|
|
371
405
|
private _awaitQrResponse;
|
|
372
|
-
|
|
373
|
-
private
|
|
374
|
-
private
|
|
406
|
+
/** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
|
|
407
|
+
private _requestQrAndAwaitResponse;
|
|
408
|
+
private _callUsbResolveUr;
|
|
375
409
|
private _runUsbTeardown;
|
|
376
410
|
private _waitForUsbOperationsToDrain;
|
|
377
411
|
private _retainUsbOperation;
|
|
378
412
|
private static _abortable;
|
|
413
|
+
/** Settles with `signal`'s reason once it aborts; a later outcome of `promise` is dropped. */
|
|
414
|
+
private static _untilAborted;
|
|
379
415
|
private static _throwIfAborted;
|
|
380
416
|
/** A response without the request's id is as unrelated as one with another id. */
|
|
381
417
|
private static _assertRequestIdMatches;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainCapability, DeviceInfo, IHardwareWallet, IConnector, TransportType, SearchDevicesOptions, DeviceSearchTarget,
|
|
1
|
+
import { ChainCapability, DeviceInfo, IHardwareWallet, IConnector, TransportType, SearchDevicesOptions, DeviceSearchTarget, Response, ChainForFingerprint, UiResponseEvent, HardwareEventMap, DeviceEventListener, AllNetworkGetAddressParams, AllNetworkAddressResponse, NullableCallArg, IHardwareCallParams, EvmGetAddressParams, EvmAddress, EvmSignTxParams, EvmSignedTx, EvmSignMsgParams, EvmSignature, EvmSignTypedDataParams, BtcGetAddressParams, BtcAddress, BtcGetPublicKeyParams, BtcPublicKey, BtcSignTxParams, BtcSignedTx, BtcSignPsbtParams, BtcSignedPsbt, BtcSignMsgParams, BtcSignature, IHardwareCommonCallParams, SolGetAddressParams, SolAddress, SolSignTxParams, SolSignedTx, SolSignMsgParams, SolSignature, TronGetAddressParams, TronAddress, TronSignTxParams, TronSignedTx, TronSignMsgParams, TronSignature } from '@onekeyfe/hwk-adapter-core';
|
|
2
2
|
|
|
3
3
|
/** Keystone `DataType`: 1 = transaction, 2 = personal message. */
|
|
4
4
|
declare enum TronSignType {
|
|
@@ -59,7 +59,7 @@ interface KeystoneBtcSignRequestAccount {
|
|
|
59
59
|
xfp: string;
|
|
60
60
|
address?: string;
|
|
61
61
|
}
|
|
62
|
-
/** Script types for purposes 44'/49'/84'/86'
|
|
62
|
+
/** Script types for purposes 44'/49'/84'/86'. */
|
|
63
63
|
type BtcScriptType = 'p2pkh' | 'p2sh-p2wpkh' | 'p2wpkh' | 'p2tr';
|
|
64
64
|
interface KeystoneSolSignRequestInput {
|
|
65
65
|
requestId: string;
|
|
@@ -134,15 +134,16 @@ declare class KeystoneUrEngine {
|
|
|
134
134
|
parseEthSignature(ur: KeystoneUr): KeystoneEthSignatureResult;
|
|
135
135
|
/** Derives an EVM address offline; `relativeDerivePath` is relative to the xpub, e.g. `'0/0'`. */
|
|
136
136
|
deriveEvmAddressFromXpub(xpub: string, relativeDerivePath: string): string;
|
|
137
|
-
/**
|
|
138
|
-
* `CryptoHDKey` always emits mainnet xpub version bytes (`0488B21E`), so `hdkey` parses it as is.
|
|
139
|
-
* `p2tr` needs an ECC lib for BIP-341 tweaking, not wired here.
|
|
140
|
-
*/
|
|
137
|
+
/** `CryptoHDKey` always emits mainnet xpub version bytes (`0488B21E`), so `hdkey` parses it as is. */
|
|
141
138
|
deriveBtcAddressFromXpub(xpub: string, relativeDerivePath: string, scriptType: BtcScriptType): string;
|
|
142
139
|
deriveBtcAddressFromPublicKey(publicKeyHex: string, scriptType: BtcScriptType): string;
|
|
143
140
|
buildBtcPsbtRequest(unsignedPsbtHex: string): KeystoneUr;
|
|
144
|
-
/**
|
|
145
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Returns the hex-encoded (possibly still-unsigned-in-part) PSBT the device replied with. A PSBT
|
|
143
|
+
* carries no request id, so the reply is bound to the request by its unsigned transaction, which
|
|
144
|
+
* signing never changes (BIP-174); a scan of another PSBT's signature is refused.
|
|
145
|
+
*/
|
|
146
|
+
parseBtcPsbt(ur: KeystoneUr, requestPsbtHex: string): string;
|
|
146
147
|
buildBtcMessageSignRequest(params: {
|
|
147
148
|
requestId: string;
|
|
148
149
|
/** Hex, no 0x prefix. */
|
|
@@ -206,8 +207,17 @@ declare function toDeviceInfo(record: KeystoneDeviceRecord): DeviceInfo;
|
|
|
206
207
|
/** Device row for a not-yet-synced wallet during a cold-start round trip. */
|
|
207
208
|
declare function placeholderDeviceInfo(): DeviceInfo;
|
|
208
209
|
|
|
209
|
-
/**
|
|
210
|
-
|
|
210
|
+
/**
|
|
211
|
+
* How an all-network item reads its key. QR: from the bundle's one scan, never the device again.
|
|
212
|
+
* USB: straight from the device, on the session the bundle started with.
|
|
213
|
+
*/
|
|
214
|
+
type BundleAccess = {
|
|
215
|
+
channel: 'qr';
|
|
216
|
+
scanned: ReadonlyMap<string, KeystoneAccountEntry>;
|
|
217
|
+
} | {
|
|
218
|
+
channel: 'usb';
|
|
219
|
+
usbSessionId: string;
|
|
220
|
+
};
|
|
211
221
|
interface ImportFromQrOptions {
|
|
212
222
|
/**
|
|
213
223
|
* 'request' asks the device for one account; 'scan' waits for whatever export it already shows.
|
|
@@ -267,7 +277,6 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
267
277
|
/** Best-effort disconnect; the session is retired either way so it cannot be selected again. */
|
|
268
278
|
private _retireUsbSession;
|
|
269
279
|
searchDeviceTargets(options?: SearchDevicesOptions): Promise<DeviceSearchTarget[]>;
|
|
270
|
-
listConnectionTargets(options?: SearchDevicesOptions): Promise<ConnectionTarget[]>;
|
|
271
280
|
connectDevice(searchTargetId: string): Promise<Response<string>>;
|
|
272
281
|
/**
|
|
273
282
|
* QR has nothing to tear down. A USB session is closed, and the record is demoted to QR-only or
|
|
@@ -277,6 +286,10 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
277
286
|
private _releaseOperationConnection;
|
|
278
287
|
getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
279
288
|
cancel(connectId?: string): void;
|
|
289
|
+
/**
|
|
290
|
+
* Derived from the wallet's master fingerprint, which the caller already holds as deviceId; the
|
|
291
|
+
* device is never asked. It names the wallet but cannot check which device is attached.
|
|
292
|
+
*/
|
|
280
293
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
281
294
|
uiResponse(response: UiResponseEvent): void;
|
|
282
295
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -284,31 +297,46 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
284
297
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
285
298
|
off(event: string, listener: DeviceEventListener): void;
|
|
286
299
|
importFromQr(options?: ImportFromQrOptions): Promise<Response<DeviceInfo>>;
|
|
300
|
+
private _importFromQr;
|
|
287
301
|
allNetworkGetAddress: (connectId: string, deviceId: string, params: AllNetworkGetAddressParams) => Promise<Response<AllNetworkAddressResponse[]>>;
|
|
288
|
-
evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
289
|
-
evmSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
290
|
-
evmSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
291
|
-
evmSignTypedData(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
292
|
-
btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
302
|
+
evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmGetAddressParams>>, bundle?: BundleAccess): Promise<Response<EvmAddress>>;
|
|
303
|
+
evmSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmSignTxParams>>): Promise<Response<EvmSignedTx>>;
|
|
304
|
+
evmSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmSignMsgParams>>): Promise<Response<EvmSignature>>;
|
|
305
|
+
evmSignTypedData(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<EvmSignTypedDataParams>>): Promise<Response<EvmSignature>>;
|
|
306
|
+
btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcGetAddressParams>>, bundle?: BundleAccess): Promise<Response<BtcAddress>>;
|
|
293
307
|
/**
|
|
294
308
|
* `params.path` must be an account path (`m/84'/0'/0'`), the level Keystone syncs. An xpub is
|
|
295
309
|
* script-type agnostic, so `86'` works here even though `btcGetAddress` rejects it.
|
|
296
310
|
*/
|
|
297
|
-
btcGetPublicKey(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
311
|
+
btcGetPublicKey(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcGetPublicKeyParams>>, bundle?: BundleAccess): Promise<Response<BtcPublicKey>>;
|
|
298
312
|
btcSignTransaction(_connectId?: NullableCallArg<string>, _deviceId?: NullableCallArg<string>, _params?: NullableCallArg<IHardwareCallParams<BtcSignTxParams>>): Promise<Response<BtcSignedTx>>;
|
|
299
|
-
btcSignPsbt(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
300
|
-
btcSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
313
|
+
btcSignPsbt(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcSignPsbtParams>>): Promise<Response<BtcSignedPsbt>>;
|
|
314
|
+
btcSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<BtcSignMsgParams>>): Promise<Response<BtcSignature>>;
|
|
315
|
+
/**
|
|
316
|
+
* Returns the known master fingerprint for the named wallet without asking the device (a QR
|
|
317
|
+
* round trip only to repeat it would cost a scan). Use it to name the wallet, for example as a
|
|
318
|
+
* PSBT xfp, which the device itself checks when signing; it cannot check the attached device.
|
|
319
|
+
*/
|
|
301
320
|
btcGetMasterFingerprint(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCommonCallParams>): Promise<Response<{
|
|
302
321
|
masterFingerprint: string;
|
|
303
322
|
}>>;
|
|
304
|
-
solGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
305
|
-
solSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
306
|
-
solSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
307
|
-
tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
308
|
-
tronSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
309
|
-
tronSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>,
|
|
323
|
+
solGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<SolGetAddressParams>>, bundle?: BundleAccess): Promise<Response<SolAddress>>;
|
|
324
|
+
solSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<SolSignTxParams>>): Promise<Response<SolSignedTx>>;
|
|
325
|
+
solSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<SolSignMsgParams>>): Promise<Response<SolSignature>>;
|
|
326
|
+
tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<TronGetAddressParams>>, bundle?: BundleAccess): Promise<Response<TronAddress>>;
|
|
327
|
+
tronSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<TronSignTxParams>>): Promise<Response<TronSignedTx>>;
|
|
328
|
+
tronSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, paramsArg?: NullableCallArg<IHardwareCallParams<TronSignMsgParams>>): Promise<Response<TronSignature>>;
|
|
329
|
+
/** Resolves the call's target and requires params, before any method-specific check. */
|
|
330
|
+
private _beginCall;
|
|
331
|
+
/** Derives a leaf address offline from its account xpub. */
|
|
332
|
+
private _addressFromAccountXpub;
|
|
333
|
+
private _evmSign;
|
|
334
|
+
private _solSign;
|
|
335
|
+
private _tronSign;
|
|
310
336
|
private _runJob;
|
|
311
337
|
private _fetchAccountXpub;
|
|
338
|
+
/** The exported key behind an address, reduced to the fields that identify it. */
|
|
339
|
+
private _exportedAccountKey;
|
|
312
340
|
/**
|
|
313
341
|
* Signing needs only the wallet's mfp: the device re-derives the key from path+xfp, so no
|
|
314
342
|
* per-path account lookup happens here.
|
|
@@ -316,11 +344,16 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
316
344
|
private _signWithWallet;
|
|
317
345
|
private _allNetworkSyncSchema;
|
|
318
346
|
/**
|
|
319
|
-
* QR answers
|
|
320
|
-
*
|
|
347
|
+
* Picks the bundle's channel. QR answers every item with one request QR and one scan; USB items
|
|
348
|
+
* each ask the device directly, like other vendors, on the session found here.
|
|
349
|
+
*/
|
|
350
|
+
private _prepareAllNetworkBundle;
|
|
351
|
+
/**
|
|
352
|
+
* A positional wallet id and an operation id must name the same wallet: otherwise the call
|
|
353
|
+
* would run on the operation's wallet while the caller files the result under the other one.
|
|
354
|
+
* Ids that do not carry a master fingerprint cannot be compared and pass through.
|
|
321
355
|
*/
|
|
322
|
-
private
|
|
323
|
-
/** Resolve the wallet's master fingerprint from the connectId and/or deviceId the caller passed. */
|
|
356
|
+
private _resolveOperationTarget;
|
|
324
357
|
private _resolveTarget;
|
|
325
358
|
private _assertParsedIdentity;
|
|
326
359
|
/**
|
|
@@ -340,16 +373,17 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
340
373
|
*/
|
|
341
374
|
private _tryUsbAttach;
|
|
342
375
|
/**
|
|
343
|
-
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session
|
|
344
|
-
* otherwise a failed USB reattach leaves the call on QR.
|
|
376
|
+
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
|
|
377
|
+
* and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
|
|
345
378
|
*/
|
|
346
379
|
private _resolveUr;
|
|
347
380
|
private _resolveUrWithRoute;
|
|
348
381
|
/** Ends the operation as disconnected and returns the error to throw. */
|
|
349
382
|
private _endDisconnectedOperation;
|
|
350
383
|
/**
|
|
351
|
-
* Fetches one account's key material
|
|
352
|
-
* failed USB export ends the operation
|
|
384
|
+
* Fetches one account's key material. An all-network QR item takes it from the bundle's scan; a
|
|
385
|
+
* USB item asks the device on the bundle's session. A failed USB export ends the operation
|
|
386
|
+
* without replaying or switching transports.
|
|
353
387
|
*/
|
|
354
388
|
private _fetchAccount;
|
|
355
389
|
/**
|
|
@@ -369,13 +403,15 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
369
403
|
* a cancel reach the wait before the QR timeout.
|
|
370
404
|
*/
|
|
371
405
|
private _awaitQrResponse;
|
|
372
|
-
|
|
373
|
-
private
|
|
374
|
-
private
|
|
406
|
+
/** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
|
|
407
|
+
private _requestQrAndAwaitResponse;
|
|
408
|
+
private _callUsbResolveUr;
|
|
375
409
|
private _runUsbTeardown;
|
|
376
410
|
private _waitForUsbOperationsToDrain;
|
|
377
411
|
private _retainUsbOperation;
|
|
378
412
|
private static _abortable;
|
|
413
|
+
/** Settles with `signal`'s reason once it aborts; a later outcome of `promise` is dropped. */
|
|
414
|
+
private static _untilAborted;
|
|
379
415
|
private static _throwIfAborted;
|
|
380
416
|
/** A response without the request's id is as unrelated as one with another id. */
|
|
381
417
|
private static _assertRequestIdMatches;
|