@onekeyfe/hwk-keystone-adapter 1.2.6-alpha.0 → 1.2.8-alpha.1

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 CHANGED
@@ -207,7 +207,17 @@ declare function toDeviceInfo(record: KeystoneDeviceRecord): DeviceInfo;
207
207
  declare function placeholderDeviceInfo(): DeviceInfo;
208
208
 
209
209
  /** Key material for one operation, keyed by `accountKey()`; never retained. */
210
- type AccountBook = Map<string, KeystoneAccountEntry>;
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.
@@ -277,6 +287,10 @@ declare class KeystoneAdapter implements IHardwareWallet {
277
287
  private _releaseOperationConnection;
278
288
  getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
279
289
  cancel(connectId?: string): void;
290
+ /**
291
+ * Derived from the wallet's master fingerprint, which the caller already holds as deviceId; the
292
+ * device is never asked. It names the wallet but cannot check which device is attached.
293
+ */
280
294
  getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
281
295
  uiResponse(response: UiResponseEvent): void;
282
296
  on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
@@ -285,26 +299,31 @@ declare class KeystoneAdapter implements IHardwareWallet {
285
299
  off(event: string, listener: DeviceEventListener): void;
286
300
  importFromQr(options?: ImportFromQrOptions): Promise<Response<DeviceInfo>>;
287
301
  allNetworkGetAddress: (connectId: string, deviceId: string, params: AllNetworkGetAddressParams) => Promise<Response<AllNetworkAddressResponse[]>>;
288
- evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmGetAddressParams>>, book?: AccountBook): Promise<Response<EvmAddress>>;
302
+ evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmGetAddressParams>>, bundle?: BundleAccess): Promise<Response<EvmAddress>>;
289
303
  evmSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmSignTxParams>>): Promise<Response<EvmSignedTx>>;
290
304
  evmSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmSignMsgParams>>): Promise<Response<EvmSignature>>;
291
305
  evmSignTypedData(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmSignTypedDataParams>>): Promise<Response<EvmSignature>>;
292
- btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<BtcGetAddressParams>>, book?: AccountBook): Promise<Response<BtcAddress>>;
306
+ btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: 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>, params?: NullableCallArg<IHardwareCallParams<BtcGetPublicKeyParams>>, book?: AccountBook): Promise<Response<BtcPublicKey>>;
311
+ btcGetPublicKey(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: 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
313
  btcSignPsbt(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<BtcSignPsbtParams>>): Promise<Response<BtcSignedPsbt>>;
300
314
  btcSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: 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>, params?: NullableCallArg<IHardwareCallParams<SolGetAddressParams>>, book?: AccountBook): Promise<Response<SolAddress>>;
323
+ solGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<SolGetAddressParams>>, bundle?: BundleAccess): Promise<Response<SolAddress>>;
305
324
  solSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<SolSignTxParams>>): Promise<Response<SolSignedTx>>;
306
325
  solSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<SolSignMsgParams>>): Promise<Response<SolSignature>>;
307
- tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronGetAddressParams>>, book?: AccountBook): Promise<Response<TronAddress>>;
326
+ tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronGetAddressParams>>, bundle?: BundleAccess): Promise<Response<TronAddress>>;
308
327
  tronSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronSignTxParams>>): Promise<Response<TronSignedTx>>;
309
328
  tronSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronSignMsgParams>>): Promise<Response<TronSignature>>;
310
329
  private _runJob;
@@ -316,11 +335,17 @@ declare class KeystoneAdapter implements IHardwareWallet {
316
335
  private _signWithWallet;
317
336
  private _allNetworkSyncSchema;
318
337
  /**
319
- * QR answers the whole bundle with one request QR and one scan. USB exports one path per
320
- * request because the device limits that channel.
338
+ * Picks the bundle's channel. QR answers every item with one request QR and one scan; USB items
339
+ * each ask the device directly, like other vendors, on the session found here.
321
340
  */
322
- private _prefetchAllNetworkAccounts;
341
+ private _prepareAllNetworkBundle;
323
342
  /** Resolve the wallet's master fingerprint from the connectId and/or deviceId the caller passed. */
343
+ /**
344
+ * A positional wallet id and an operation id must name the same wallet: otherwise the call
345
+ * would run on the operation's wallet while the caller files the result under the other one.
346
+ * Ids that do not carry a master fingerprint cannot be compared and pass through.
347
+ */
348
+ private _resolveOperationTarget;
324
349
  private _resolveTarget;
325
350
  private _assertParsedIdentity;
326
351
  /**
@@ -340,16 +365,17 @@ declare class KeystoneAdapter implements IHardwareWallet {
340
365
  */
341
366
  private _tryUsbAttach;
342
367
  /**
343
- * Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session fails closed;
344
- * otherwise a failed USB reattach leaves the call on QR.
368
+ * Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
369
+ * and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
345
370
  */
346
371
  private _resolveUr;
347
372
  private _resolveUrWithRoute;
348
373
  /** Ends the operation as disconnected and returns the error to throw. */
349
374
  private _endDisconnectedOperation;
350
375
  /**
351
- * Fetches one account's key material for this operation only; `book` reuses earlier fetches. A
352
- * failed USB export ends the operation without replaying or switching transports.
376
+ * Fetches one account's key material. An all-network QR item takes it from the bundle's scan; a
377
+ * USB item asks the device on the bundle's session. A failed USB export ends the operation
378
+ * without replaying or switching transports.
353
379
  */
354
380
  private _fetchAccount;
355
381
  /**
package/dist/index.d.ts CHANGED
@@ -207,7 +207,17 @@ declare function toDeviceInfo(record: KeystoneDeviceRecord): DeviceInfo;
207
207
  declare function placeholderDeviceInfo(): DeviceInfo;
208
208
 
209
209
  /** Key material for one operation, keyed by `accountKey()`; never retained. */
210
- type AccountBook = Map<string, KeystoneAccountEntry>;
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.
@@ -277,6 +287,10 @@ declare class KeystoneAdapter implements IHardwareWallet {
277
287
  private _releaseOperationConnection;
278
288
  getDeviceInfo(connectIdOrOperationId: string, deviceId: string): Promise<Response<DeviceInfo>>;
279
289
  cancel(connectId?: string): void;
290
+ /**
291
+ * Derived from the wallet's master fingerprint, which the caller already holds as deviceId; the
292
+ * device is never asked. It names the wallet but cannot check which device is attached.
293
+ */
280
294
  getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
281
295
  uiResponse(response: UiResponseEvent): void;
282
296
  on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
@@ -285,26 +299,31 @@ declare class KeystoneAdapter implements IHardwareWallet {
285
299
  off(event: string, listener: DeviceEventListener): void;
286
300
  importFromQr(options?: ImportFromQrOptions): Promise<Response<DeviceInfo>>;
287
301
  allNetworkGetAddress: (connectId: string, deviceId: string, params: AllNetworkGetAddressParams) => Promise<Response<AllNetworkAddressResponse[]>>;
288
- evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmGetAddressParams>>, book?: AccountBook): Promise<Response<EvmAddress>>;
302
+ evmGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmGetAddressParams>>, bundle?: BundleAccess): Promise<Response<EvmAddress>>;
289
303
  evmSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmSignTxParams>>): Promise<Response<EvmSignedTx>>;
290
304
  evmSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmSignMsgParams>>): Promise<Response<EvmSignature>>;
291
305
  evmSignTypedData(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<EvmSignTypedDataParams>>): Promise<Response<EvmSignature>>;
292
- btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<BtcGetAddressParams>>, book?: AccountBook): Promise<Response<BtcAddress>>;
306
+ btcGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: 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>, params?: NullableCallArg<IHardwareCallParams<BtcGetPublicKeyParams>>, book?: AccountBook): Promise<Response<BtcPublicKey>>;
311
+ btcGetPublicKey(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: 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
313
  btcSignPsbt(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<BtcSignPsbtParams>>): Promise<Response<BtcSignedPsbt>>;
300
314
  btcSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: 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>, params?: NullableCallArg<IHardwareCallParams<SolGetAddressParams>>, book?: AccountBook): Promise<Response<SolAddress>>;
323
+ solGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<SolGetAddressParams>>, bundle?: BundleAccess): Promise<Response<SolAddress>>;
305
324
  solSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<SolSignTxParams>>): Promise<Response<SolSignedTx>>;
306
325
  solSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<SolSignMsgParams>>): Promise<Response<SolSignature>>;
307
- tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronGetAddressParams>>, book?: AccountBook): Promise<Response<TronAddress>>;
326
+ tronGetAddress(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronGetAddressParams>>, bundle?: BundleAccess): Promise<Response<TronAddress>>;
308
327
  tronSignTransaction(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronSignTxParams>>): Promise<Response<TronSignedTx>>;
309
328
  tronSignMessage(connectIdArg?: NullableCallArg<string>, deviceIdArg?: NullableCallArg<string>, params?: NullableCallArg<IHardwareCallParams<TronSignMsgParams>>): Promise<Response<TronSignature>>;
310
329
  private _runJob;
@@ -316,11 +335,17 @@ declare class KeystoneAdapter implements IHardwareWallet {
316
335
  private _signWithWallet;
317
336
  private _allNetworkSyncSchema;
318
337
  /**
319
- * QR answers the whole bundle with one request QR and one scan. USB exports one path per
320
- * request because the device limits that channel.
338
+ * Picks the bundle's channel. QR answers every item with one request QR and one scan; USB items
339
+ * each ask the device directly, like other vendors, on the session found here.
321
340
  */
322
- private _prefetchAllNetworkAccounts;
341
+ private _prepareAllNetworkBundle;
323
342
  /** Resolve the wallet's master fingerprint from the connectId and/or deviceId the caller passed. */
343
+ /**
344
+ * A positional wallet id and an operation id must name the same wallet: otherwise the call
345
+ * would run on the operation's wallet while the caller files the result under the other one.
346
+ * Ids that do not carry a master fingerprint cannot be compared and pass through.
347
+ */
348
+ private _resolveOperationTarget;
324
349
  private _resolveTarget;
325
350
  private _assertParsedIdentity;
326
351
  /**
@@ -340,16 +365,17 @@ declare class KeystoneAdapter implements IHardwareWallet {
340
365
  */
341
366
  private _tryUsbAttach;
342
367
  /**
343
- * Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session fails closed;
344
- * otherwise a failed USB reattach leaves the call on QR.
368
+ * Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
369
+ * and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
345
370
  */
346
371
  private _resolveUr;
347
372
  private _resolveUrWithRoute;
348
373
  /** Ends the operation as disconnected and returns the error to throw. */
349
374
  private _endDisconnectedOperation;
350
375
  /**
351
- * Fetches one account's key material for this operation only; `book` reuses earlier fetches. A
352
- * failed USB export ends the operation without replaying or switching transports.
376
+ * Fetches one account's key material. An all-network QR item takes it from the bundle's scan; a
377
+ * USB item asks the device on the bundle's session. A failed USB export ends the operation
378
+ * without replaying or switching transports.
353
379
  */
354
380
  private _fetchAccount;
355
381
  /**