@bytezhang/hardware-wallet-core 0.0.28 → 0.0.30
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 +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -663,7 +663,7 @@ interface IUiHandler {
|
|
|
663
663
|
context?: Record<string, unknown>;
|
|
664
664
|
}): Promise<void>;
|
|
665
665
|
}
|
|
666
|
-
interface IHardwareWallet<TConfig = unknown>
|
|
666
|
+
interface IHardwareWallet<TConfig = unknown> {
|
|
667
667
|
readonly vendor: string;
|
|
668
668
|
readonly activeTransport: TransportType | null;
|
|
669
669
|
init(config: TConfig): Promise<void>;
|
|
@@ -676,6 +676,10 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
676
676
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
677
677
|
getSupportedChains(): ChainCapability[];
|
|
678
678
|
cancel(connectId: string): void;
|
|
679
|
+
evm(): IEvmMethods | null;
|
|
680
|
+
btc(): IBtcMethods | null;
|
|
681
|
+
sol(): ISolMethods | null;
|
|
682
|
+
tron(): ITronMethods | null;
|
|
679
683
|
/**
|
|
680
684
|
* Derive a chain-specific fingerprint for the connected device.
|
|
681
685
|
*
|
|
@@ -809,6 +813,20 @@ interface ConnectorSession {
|
|
|
809
813
|
deviceInfo: DeviceInfo;
|
|
810
814
|
}
|
|
811
815
|
type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
|
|
816
|
+
/**
|
|
817
|
+
* Interaction event types emitted via 'ui-event'.
|
|
818
|
+
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
819
|
+
*/
|
|
820
|
+
declare enum EConnectorInteraction {
|
|
821
|
+
/** Device requires user to open a specific app */
|
|
822
|
+
ConfirmOpenApp = "confirm-open-app",
|
|
823
|
+
/** Device requires user to unlock */
|
|
824
|
+
UnlockDevice = "unlock-device",
|
|
825
|
+
/** Device needs user to confirm on device (sign, verify, etc.) */
|
|
826
|
+
ConfirmOnDevice = "confirm-on-device",
|
|
827
|
+
/** Previous interaction completed — clear UI prompt */
|
|
828
|
+
InteractionComplete = "interaction-complete"
|
|
829
|
+
}
|
|
812
830
|
interface ConnectorEventMap {
|
|
813
831
|
'device-connect': {
|
|
814
832
|
device: ConnectorDevice;
|
|
@@ -923,4 +941,4 @@ declare class TypedEventEmitter<TMap extends Record<string, any> = Record<string
|
|
|
923
941
|
*/
|
|
924
942
|
declare function compareSemver(a: string, b: string): number;
|
|
925
943
|
|
|
926
|
-
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, 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 IDesktopHardwareBridge, type IEvmMethods, 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, compareSemver, createDesktopBridgeConnector, deriveDeviceFingerprint, failure, success };
|
|
944
|
+
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 IDesktopHardwareBridge, type IEvmMethods, 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, compareSemver, createDesktopBridgeConnector, deriveDeviceFingerprint, failure, success };
|
package/dist/index.d.ts
CHANGED
|
@@ -663,7 +663,7 @@ interface IUiHandler {
|
|
|
663
663
|
context?: Record<string, unknown>;
|
|
664
664
|
}): Promise<void>;
|
|
665
665
|
}
|
|
666
|
-
interface IHardwareWallet<TConfig = unknown>
|
|
666
|
+
interface IHardwareWallet<TConfig = unknown> {
|
|
667
667
|
readonly vendor: string;
|
|
668
668
|
readonly activeTransport: TransportType | null;
|
|
669
669
|
init(config: TConfig): Promise<void>;
|
|
@@ -676,6 +676,10 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
676
676
|
getDeviceInfo(connectId: string, deviceId: string): Promise<Response<DeviceInfo>>;
|
|
677
677
|
getSupportedChains(): ChainCapability[];
|
|
678
678
|
cancel(connectId: string): void;
|
|
679
|
+
evm(): IEvmMethods | null;
|
|
680
|
+
btc(): IBtcMethods | null;
|
|
681
|
+
sol(): ISolMethods | null;
|
|
682
|
+
tron(): ITronMethods | null;
|
|
679
683
|
/**
|
|
680
684
|
* Derive a chain-specific fingerprint for the connected device.
|
|
681
685
|
*
|
|
@@ -809,6 +813,20 @@ interface ConnectorSession {
|
|
|
809
813
|
deviceInfo: DeviceInfo;
|
|
810
814
|
}
|
|
811
815
|
type ConnectorEventType = 'device-connect' | 'device-disconnect' | 'ui-request' | 'ui-event';
|
|
816
|
+
/**
|
|
817
|
+
* Interaction event types emitted via 'ui-event'.
|
|
818
|
+
* These map to user-facing prompts (confirm on device, open app, etc.).
|
|
819
|
+
*/
|
|
820
|
+
declare enum EConnectorInteraction {
|
|
821
|
+
/** Device requires user to open a specific app */
|
|
822
|
+
ConfirmOpenApp = "confirm-open-app",
|
|
823
|
+
/** Device requires user to unlock */
|
|
824
|
+
UnlockDevice = "unlock-device",
|
|
825
|
+
/** Device needs user to confirm on device (sign, verify, etc.) */
|
|
826
|
+
ConfirmOnDevice = "confirm-on-device",
|
|
827
|
+
/** Previous interaction completed — clear UI prompt */
|
|
828
|
+
InteractionComplete = "interaction-complete"
|
|
829
|
+
}
|
|
812
830
|
interface ConnectorEventMap {
|
|
813
831
|
'device-connect': {
|
|
814
832
|
device: ConnectorDevice;
|
|
@@ -923,4 +941,4 @@ declare class TypedEventEmitter<TMap extends Record<string, any> = Record<string
|
|
|
923
941
|
*/
|
|
924
942
|
declare function compareSemver(a: string, b: string): number;
|
|
925
943
|
|
|
926
|
-
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, 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 IDesktopHardwareBridge, type IEvmMethods, 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, compareSemver, createDesktopBridgeConnector, deriveDeviceFingerprint, failure, success };
|
|
944
|
+
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 IDesktopHardwareBridge, type IEvmMethods, 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, compareSemver, createDesktopBridgeConnector, deriveDeviceFingerprint, failure, success };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(index_exports, {
|
|
|
24
24
|
DEVICE: () => DEVICE,
|
|
25
25
|
DEVICE_EVENT: () => DEVICE_EVENT,
|
|
26
26
|
DeviceJobQueue: () => DeviceJobQueue,
|
|
27
|
+
EConnectorInteraction: () => EConnectorInteraction,
|
|
27
28
|
HardwareErrorCode: () => HardwareErrorCode,
|
|
28
29
|
SDK: () => SDK,
|
|
29
30
|
TypedEventEmitter: () => TypedEventEmitter,
|
|
@@ -256,6 +257,13 @@ var DeviceJobQueue = class {
|
|
|
256
257
|
};
|
|
257
258
|
|
|
258
259
|
// src/types/connector.ts
|
|
260
|
+
var EConnectorInteraction = /* @__PURE__ */ ((EConnectorInteraction2) => {
|
|
261
|
+
EConnectorInteraction2["ConfirmOpenApp"] = "confirm-open-app";
|
|
262
|
+
EConnectorInteraction2["UnlockDevice"] = "unlock-device";
|
|
263
|
+
EConnectorInteraction2["ConfirmOnDevice"] = "confirm-on-device";
|
|
264
|
+
EConnectorInteraction2["InteractionComplete"] = "interaction-complete";
|
|
265
|
+
return EConnectorInteraction2;
|
|
266
|
+
})(EConnectorInteraction || {});
|
|
259
267
|
function createDesktopBridgeConnector(vendor, bridge) {
|
|
260
268
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
261
269
|
return {
|
|
@@ -342,6 +350,7 @@ function compareSemver(a, b) {
|
|
|
342
350
|
DEVICE,
|
|
343
351
|
DEVICE_EVENT,
|
|
344
352
|
DeviceJobQueue,
|
|
353
|
+
EConnectorInteraction,
|
|
345
354
|
HardwareErrorCode,
|
|
346
355
|
SDK,
|
|
347
356
|
TypedEventEmitter,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/errors.ts","../src/types/response.ts","../src/types/fingerprint.ts","../src/events/device.ts","../src/events/ui-request.ts","../src/events/sdk.ts","../src/utils/DeviceJobQueue.ts","../src/types/connector.ts","../src/utils/TypedEventEmitter.ts","../src/utils/semver.ts"],"sourcesContent":["export { HardwareErrorCode } from './types/errors';\n\nexport type { Success, Failure, Response } from './types/response';\nexport { success, failure } from './types/response';\n\nexport type { VendorType, ConnectionType, TransportType, DeviceInfo, DeviceTarget, DeviceCapabilities } from './types/device';\n\nexport type {\n EvmGetAddressParams,\n EvmAddress,\n EvmGetPublicKeyParams,\n EvmPublicKey,\n EvmSignTxParams,\n EvmSignedTx,\n EvmSignMsgParams,\n EvmSignTypedDataParams,\n EvmSignTypedDataFull,\n EvmSignTypedDataHash,\n EIP712Domain,\n EvmSignature,\n ProgressCallback,\n IEvmMethods,\n} from './types/chain-evm';\n\nexport type {\n BtcGetAddressParams,\n BtcAddress,\n BtcGetPublicKeyParams,\n BtcPublicKey,\n BtcSignTxParams,\n BtcTxInput,\n BtcTxOutput,\n BtcRefTransaction,\n BtcSignedTx,\n BtcSignMsgParams,\n BtcSignature,\n IBtcMethods,\n} from './types/chain-btc';\n\nexport type {\n SolGetAddressParams,\n SolAddress,\n SolGetPublicKeyParams,\n SolPublicKey,\n SolSignTxParams,\n SolSignedTx,\n SolSignMsgParams,\n SolSignature,\n ISolMethods,\n} from './types/chain-sol';\n\nexport type {\n TronGetAddressParams,\n TronAddress,\n TronSignTxParams,\n TronSignedTx,\n TronSignMsgParams,\n TronSignature,\n ITronMethods,\n} from './types/chain-tron';\n\nexport type { QrDisplayData, QrResponseData } from './types/qr';\n\nexport type { ChainForFingerprint } from './types/fingerprint';\nexport { CHAIN_FINGERPRINT_PATHS, deriveDeviceFingerprint } from './types/fingerprint';\n\nexport type {\n IHardwareWallet,\n IUiHandler,\n PassphraseResponse,\n ChainCapability,\n DeviceEvent,\n UiRequestEvent,\n SdkEvent,\n HardwareEvent,\n HardwareEventMap,\n DeviceEventListener,\n} from './types/wallet';\n\nexport { DEVICE_EVENT, DEVICE } from './events/device';\nexport { UI_EVENT, UI_REQUEST, UI_RESPONSE } from './events/ui-request';\nexport { SDK } from './events/sdk';\n\nexport type {\n DeviceDescriptor,\n DeviceConnectEvent,\n DeviceDisconnectEvent,\n DeviceChangeEvent,\n} from './types/transport';\n\nexport { DeviceJobQueue } from './utils/DeviceJobQueue';\nexport type {\n Interruptibility,\n PreemptionDecision,\n JobOptions,\n ActiveJobInfo,\n PreemptionEvent,\n} from './utils/DeviceJobQueue';\nexport type { IUiBridge } from './types/ui-bridge';\n\nexport type {\n ConnectorDevice,\n ConnectorSession,\n ConnectorEventType,\n ConnectorEventMap,\n IConnector,\n IDesktopHardwareBridge,\n} from './types/connector';\nexport { createDesktopBridgeConnector } from './types/connector';\n\nexport { TypedEventEmitter } from './utils/TypedEventEmitter';\nexport { compareSemver } from './utils/semver';\n","export enum HardwareErrorCode {\n UnknownError = 0,\n DeviceNotFound = 1,\n DeviceDisconnected = 2,\n UserRejected = 3,\n DeviceBusy = 4,\n FirmwareUpdateRequired = 5,\n AppNotOpen = 6,\n InvalidParams = 7,\n TransportError = 8,\n OperationTimeout = 9,\n MethodNotSupported = 10,\n\n // PIN / Passphrase\n PinInvalid = 5520,\n PinCancelled = 5521,\n PassphraseRejected = 5522,\n\n // Device state\n DeviceLocked = 5530,\n DeviceNotInitialized = 5531,\n DeviceInBootloader = 5532,\n FirmwareTooOld = 5533,\n\n // Ledger specific\n WrongApp = 5540,\n\n // Device identity\n DeviceMismatch = 5560,\n\n // Transport\n BridgeNotFound = 5550,\n TransportNotAvailable = 5551,\n}\n","import { HardwareErrorCode } from './errors';\n\nexport interface Success<T> {\n success: true;\n payload: T;\n}\n\nexport interface Failure {\n success: false;\n payload: {\n error: string;\n code: HardwareErrorCode;\n };\n}\n\nexport type Response<T> = Success<T> | Failure;\n\nexport function success<T>(payload: T): Success<T> {\n return { success: true, payload };\n}\n\nexport function failure(code: HardwareErrorCode, error: string): Failure {\n return { success: false, payload: { error, code } };\n}\n","/**\n * Chain fingerprint utilities for device identity verification.\n *\n * Ledger devices have ephemeral IDs that change every session.\n * To verify that the same seed/device is connected, we derive an address\n * at a fixed path (account 0, index 0) and hash it into a stable \"chain fingerprint\".\n */\n\n/**\n * Fixed derivation paths used to generate chain fingerprints.\n * Uses standard index 0 — Ledger firmware shows device confirmation for\n * non-standard paths (e.g., index=100), which would interrupt wallet creation.\n * The address is hashed into a 16-char fingerprint, not exposed directly.\n * - EVM: cointype 60 (Ledger ETH App only supports 60)\n * - BTC: cointype 1 (testnet)\n * - SOL: cointype 501, standard 3-level hardened\n */\nexport const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string> = {\n evm: \"m/44'/60'/0'/0/0\",\n // BTC: account-level path (3 levels), mainnet cointype 0.\n // Cointype 1 (testnet) is rejected by some Ledger BTC App configurations.\n btc: \"m/44'/0'/0'\",\n sol: \"m/44'/501'/0'\",\n tron: \"m/44'/195'/0'/0/0\",\n};\n\nexport type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';\n\n/**\n * Hash an address string into a 16-character hex fingerprint.\n *\n * Uses a simple non-cryptographic hash (FNV-1a based) to avoid\n * pulling in a SHA-256 dependency. This is NOT used for security —\n * only for device identity matching.\n */\nexport function deriveDeviceFingerprint(address: string): string {\n // FNV-1a 64-bit constants (split into two 32-bit halves for JS)\n let h1 = 0x811c9dc5;\n let h2 = 0x01000193;\n\n for (let i = 0; i < address.length; i++) {\n const c = address.charCodeAt(i);\n h1 = Math.imul(h1 ^ c, h2);\n h2 = Math.imul(h2 ^ (c >>> 4), 0x01000193);\n }\n\n // Mix the two halves for better distribution\n h1 = Math.imul(h1 ^ (h1 >>> 16), 0x45d9f3b);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 0x45d9f3b);\n\n const hex1 = (h1 >>> 0).toString(16).padStart(8, '0');\n const hex2 = (h2 >>> 0).toString(16).padStart(8, '0');\n\n return `${hex1}${hex2}`;\n}\n","export const DEVICE_EVENT = 'DEVICE_EVENT';\n\n/** Events originating from the hardware device. */\nexport const DEVICE = {\n CONNECT: 'device-connect',\n DISCONNECT: 'device-disconnect',\n CHANGED: 'device-changed',\n ACQUIRE: 'device-acquire',\n RELEASE: 'device-release',\n FEATURES: 'features',\n SUPPORT_FEATURES: 'support_features',\n} as const;\n","export const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request-passphrase-on-device',\n REQUEST_BUTTON: 'ui-request-button',\n REQUEST_QR_DISPLAY: 'ui-request-qr-display',\n REQUEST_QR_SCAN: 'ui-request-qr-scan',\n REQUEST_DEVICE_PERMISSION: 'ui-request-device-permission',\n REQUEST_SELECT_DEVICE: 'ui-request-select-device',\n CLOSE_UI_WINDOW: 'ui-close',\n DEVICE_PROGRESS: 'ui-device_progress',\n FIRMWARE_PROGRESS: 'ui-firmware-progress',\n FIRMWARE_TIP: 'ui-firmware-tip',\n} as const;\n\nexport const UI_RESPONSE = {\n RECEIVE_PIN: 'receive-pin',\n RECEIVE_PASSPHRASE: 'receive-passphrase',\n RECEIVE_PASSPHRASE_ON_DEVICE: 'receive-passphrase-on-device',\n RECEIVE_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n CANCEL: 'cancel',\n} as const;\n","/** Events generated by SDK internal detection (not from hardware directly). */\nexport const SDK = {\n DEVICE_STUCK: 'device-stuck',\n DEVICE_UNRESPONSIVE: 'device-unresponsive',\n DEVICE_RECOVERED: 'device-recovered',\n DEVICE_INTERACTION: 'device-interaction',\n} as const;\n","/**\n * Per-device serial job queue with preemption support and stuck recovery.\n * Ensures that only one operation runs at a time per device, with intelligent\n * handling of conflicting operations.\n */\n\nexport type Interruptibility = 'none' | 'safe' | 'confirm';\n\nexport type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';\n\nexport interface JobOptions {\n interruptibility?: Interruptibility;\n label?: string;\n}\n\nexport interface ActiveJobInfo {\n label?: string;\n interruptibility: Interruptibility;\n startedAt: number;\n}\n\nexport interface PreemptionEvent {\n deviceId: string;\n currentJob: ActiveJobInfo;\n newJob: { label?: string; interruptibility: Interruptibility };\n}\n\ninterface ActiveJob {\n options: Required<Pick<JobOptions, 'interruptibility'>> & Pick<JobOptions, 'label'>;\n abortController: AbortController;\n startedAt: number;\n}\n\nexport class DeviceJobQueue {\n private readonly _queues = new Map<string, Promise<unknown>>();\n private readonly _active = new Map<string, ActiveJob>();\n\n /**\n * Called when a new job conflicts with an active 'confirm'-level job.\n * UI should show a dialog and return the user's decision.\n * If not set, defaults to 'wait' (queue behind current job).\n */\n onPreemptionRequest?: (event: PreemptionEvent) => Promise<PreemptionDecision>;\n\n /**\n * Enqueue a job for a specific device.\n * If a job is already running for this device, behavior depends on interruptibility:\n * - 'none': new job queues silently (no preemption possible)\n * - 'safe': current job is auto-cancelled, new job runs immediately after\n * - 'confirm': onPreemptionRequest is called to ask user\n */\n async enqueue<T>(\n deviceId: string,\n job: (signal: AbortSignal) => Promise<T>,\n options: JobOptions = {},\n ): Promise<T> {\n const interruptibility = options.interruptibility ?? 'confirm';\n const active = this._active.get(deviceId);\n\n if (active) {\n switch (active.options.interruptibility) {\n case 'none':\n // Cannot interrupt, just queue behind\n break;\n case 'safe':\n // Auto-cancel current safe operation\n active.abortController.abort(new Error('Preempted by new operation'));\n break;\n case 'confirm': {\n if (this.onPreemptionRequest) {\n const decision = await this.onPreemptionRequest({\n deviceId,\n currentJob: {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n },\n newJob: {\n label: options.label,\n interruptibility,\n },\n });\n switch (decision) {\n case 'cancel-current':\n active.abortController.abort(new Error('Cancelled by user via preemption'));\n break;\n case 'reject-new':\n throw Object.assign(\n new Error(`Device busy: ${active.options.label ?? 'unknown operation'}`),\n { hardwareErrorCode: 'DEVICE_BUSY' },\n );\n case 'wait':\n break;\n }\n }\n break;\n }\n }\n }\n\n const ac = new AbortController();\n const prev = this._queues.get(deviceId) ?? Promise.resolve();\n\n const next = prev.catch(() => {}).then(async () => {\n this._active.set(deviceId, {\n options: { interruptibility, label: options.label },\n abortController: ac,\n startedAt: Date.now(),\n });\n try {\n return await job(ac.signal);\n } finally {\n this._active.delete(deviceId);\n }\n });\n\n const tail = next.catch(() => {});\n this._queues.set(deviceId, tail);\n tail.then(() => {\n if (this._queues.get(deviceId) === tail) {\n this._queues.delete(deviceId);\n }\n });\n return next;\n }\n\n /** Manually cancel the active job on a device. Returns false if job is non-interruptible. */\n cancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n if (active.options.interruptibility === 'none') return false;\n active.abortController.abort(new Error('Manually cancelled'));\n return true;\n }\n\n /** Force cancel regardless of interruptibility. Use for device stuck recovery. */\n forceCancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n active.abortController.abort(new Error('Force cancelled for recovery'));\n return true;\n }\n\n /** Get info about the currently active job for a device, or null if idle. */\n getActiveJob(deviceId: string): ActiveJobInfo | null {\n const active = this._active.get(deviceId);\n if (!active) return null;\n return {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n };\n }\n\n clear(): void {\n // Abort all active jobs\n for (const active of this._active.values()) {\n active.abortController.abort(new Error('Queue cleared'));\n }\n this._active.clear();\n this._queues.clear();\n }\n}\n","import type { DeviceCapabilities, DeviceInfo, VendorType } from './device';\n\n// =====================================================================\n// Connector types — transport-level abstraction for device communication\n// =====================================================================\n\n/**\n * Minimal device info returned during discovery (searchDevices).\n * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.\n */\nexport interface ConnectorDevice {\n connectId: string;\n deviceId: string;\n name: string;\n model?: string;\n\n /** Device capabilities — available from scan time */\n capabilities?: DeviceCapabilities;\n}\n\nexport interface ConnectorSession {\n sessionId: string;\n deviceInfo: DeviceInfo;\n}\n\nexport type ConnectorEventType =\n | 'device-connect'\n | 'device-disconnect'\n | 'ui-request'\n | 'ui-event';\n\nexport interface ConnectorEventMap {\n 'device-connect': { device: ConnectorDevice };\n 'device-disconnect': { connectId: string };\n 'ui-request': { type: string; payload?: unknown };\n 'ui-event': { type: string; payload?: unknown };\n}\n\nexport interface IConnector {\n searchDevices(): Promise<ConnectorDevice[]>;\n connect(deviceId?: string): Promise<ConnectorSession>;\n disconnect(sessionId: string): Promise<void>;\n call(sessionId: string, method: string, params: unknown): Promise<unknown>;\n cancel(sessionId: string): Promise<void>;\n\n /** Send a UI response (e.g. PIN, passphrase) to the device. */\n uiResponse(response: { type: string; payload: unknown }): void;\n\n on<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n off<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n\n reset(): void;\n}\n\n// =====================================================================\n// Desktop IPC bridge — generic interface for main-process hardware access\n// =====================================================================\n\nexport interface IDesktopHardwareBridge {\n searchDevices(params: { vendor: VendorType }): Promise<ConnectorDevice[]>;\n connect(params: {\n vendor: VendorType;\n deviceId?: string;\n }): Promise<ConnectorSession>;\n disconnect(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n call(params: {\n vendor: VendorType;\n sessionId: string;\n method: string;\n callParams: unknown;\n }): Promise<unknown>;\n cancel(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n uiResponse(params: {\n vendor: VendorType;\n response: { type: string; payload: unknown };\n }): void;\n reset(params: { vendor: VendorType }): void;\n\n /** Register an event handler for connector events forwarded from the main process. */\n onEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n\n /** Unregister a previously registered event handler. */\n offEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n}\n\n/**\n * Create an IConnector from a desktop IPC bridge + vendor name.\n * Events are forwarded via bridge.onEvent/offEvent.\n */\nexport function createDesktopBridgeConnector(\n vendor: VendorType,\n bridge: IDesktopHardwareBridge,\n): IConnector {\n // Map from typed IConnector handlers to the bridge handler so we can\n // unregister them correctly via off().\n const handlerMap = new Map<\n (data: ConnectorEventMap[ConnectorEventType]) => void,\n (event: { type: ConnectorEventType; data: unknown }) => void\n >();\n\n return {\n searchDevices: () => bridge.searchDevices({ vendor }),\n connect: (deviceId) => bridge.connect({ vendor, deviceId }),\n disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),\n call: (sessionId, method, callParams) =>\n bridge.call({ vendor, sessionId, method, callParams }),\n cancel: (sessionId) => bridge.cancel({ vendor, sessionId }),\n uiResponse: (response) => bridge.uiResponse({ vendor, response }),\n on: (event, handler) => {\n const bridgeHandler = (e: { type: ConnectorEventType; data: unknown }) => {\n if (e.type === event) {\n handler(e.data as ConnectorEventMap[typeof event]);\n }\n };\n handlerMap.set(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n bridgeHandler,\n );\n bridge.onEvent({ vendor }, bridgeHandler);\n },\n off: (_event, handler) => {\n const bridgeHandler = handlerMap.get(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n if (bridgeHandler) {\n bridge.offEvent({ vendor }, bridgeHandler);\n handlerMap.delete(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n }\n },\n reset: () => bridge.reset({ vendor }),\n };\n}\n","/**\n * Minimal typed event emitter using Map<string, Set<listener>>.\n * Each adapter uses this for device events (connect, disconnect, pin, etc.).\n *\n * TMap is a record mapping event name strings to their payload types.\n * Example:\n * type MyEvents = { 'connect': { id: string }; 'disconnect': { id: string } };\n * const emitter = new TypedEventEmitter<MyEvents>();\n * emitter.on('connect', (data) => { data.id }); // data is { id: string }\n *\n * For backward compatibility, TMap defaults to Record<string, any> so that\n * existing code using `new TypedEventEmitter<SomeUnionType>()` still compiles.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class TypedEventEmitter<TMap extends Record<string, any> = Record<string, any>> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly _listeners = new Map<string, Set<(event: any) => void>>();\n\n on<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n on(event: string, listener: (event: any) => void): void;\n on(event: string, listener: (event: any) => void): void {\n let set = this._listeners.get(event);\n if (!set) {\n set = new Set();\n this._listeners.set(event, set);\n }\n set.add(listener);\n }\n\n off<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n off(event: string, listener: (event: any) => void): void;\n off(event: string, listener: (event: any) => void): void {\n const set = this._listeners.get(event);\n if (set) {\n set.delete(listener);\n if (set.size === 0) this._listeners.delete(event);\n }\n }\n\n emit<K extends keyof TMap & string>(event: K, data: TMap[K]): void;\n emit(event: string, data: unknown): void;\n emit(event: string, data: unknown): void {\n const set = this._listeners.get(event);\n if (set) {\n for (const listener of set) listener(data);\n }\n }\n\n removeAllListeners(): void {\n this._listeners.clear();\n }\n}\n","/**\n * Compare two semver strings (e.g. \"2.1.0\" vs \"2.3.1\").\n * Returns -1 if a < b, 0 if equal, 1 if a > b.\n */\nexport function compareSemver(a: string, b: string): number {\n const pa = a.split('.').map(Number);\n const pb = b.split('.').map(Number);\n for (let i = 0; i < 3; i++) {\n const va = pa[i] ?? 0;\n const vb = pb[i] ?? 0;\n if (va < vb) return -1;\n if (va > vb) return 1;\n }\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,sCAAA,kBAAe,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AChC;AACA,QAAI,IAAI,QAAQ;AAAA,EAClB;AAAA,EAIA,IAAI,OAAe,UAAsC;AACvD,UAAM,MAAM,KAAK,WAAW,IAAI,KAAK;AACrC,QAAI,KAAK;AACP,UAAI,OAAO,QAAQ;AACnB,UAAI,IAAI,SAAS,EAAG,MAAK,WAAW,OAAO,KAAK;AAAA,IAClD;AAAA,EACF;AAAA,EAIA,KAAK,OAAe,MAAqB;AACvC,UAAM,MAAM,KAAK,WAAW,IAAI,KAAK;AACrC,QAAI,KAAK;AACP,iBAAW,YAAY,IAAK,UAAS,IAAI;AAAA,IAC3C;AAAA,EACF;AAAA,EAEA,qBAA2B;AACzB,SAAK,WAAW,MAAM;AAAA,EACxB;AACF;;;AC/CO,SAAS,cAAc,GAAW,GAAmB;AAC1D,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,QAAI,KAAK,GAAI,QAAO;AACpB,QAAI,KAAK,GAAI,QAAO;AAAA,EACtB;AACA,SAAO;AACT;","names":["HardwareErrorCode"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/errors.ts","../src/types/response.ts","../src/types/fingerprint.ts","../src/events/device.ts","../src/events/ui-request.ts","../src/events/sdk.ts","../src/utils/DeviceJobQueue.ts","../src/types/connector.ts","../src/utils/TypedEventEmitter.ts","../src/utils/semver.ts"],"sourcesContent":["export { HardwareErrorCode } from './types/errors';\n\nexport type { Success, Failure, Response } from './types/response';\nexport { success, failure } from './types/response';\n\nexport type { VendorType, ConnectionType, TransportType, DeviceInfo, DeviceTarget, DeviceCapabilities } from './types/device';\n\nexport type {\n EvmGetAddressParams,\n EvmAddress,\n EvmGetPublicKeyParams,\n EvmPublicKey,\n EvmSignTxParams,\n EvmSignedTx,\n EvmSignMsgParams,\n EvmSignTypedDataParams,\n EvmSignTypedDataFull,\n EvmSignTypedDataHash,\n EIP712Domain,\n EvmSignature,\n ProgressCallback,\n IEvmMethods,\n} from './types/chain-evm';\n\nexport type {\n BtcGetAddressParams,\n BtcAddress,\n BtcGetPublicKeyParams,\n BtcPublicKey,\n BtcSignTxParams,\n BtcTxInput,\n BtcTxOutput,\n BtcRefTransaction,\n BtcSignedTx,\n BtcSignMsgParams,\n BtcSignature,\n IBtcMethods,\n} from './types/chain-btc';\n\nexport type {\n SolGetAddressParams,\n SolAddress,\n SolGetPublicKeyParams,\n SolPublicKey,\n SolSignTxParams,\n SolSignedTx,\n SolSignMsgParams,\n SolSignature,\n ISolMethods,\n} from './types/chain-sol';\n\nexport type {\n TronGetAddressParams,\n TronAddress,\n TronSignTxParams,\n TronSignedTx,\n TronSignMsgParams,\n TronSignature,\n ITronMethods,\n} from './types/chain-tron';\n\nexport type { QrDisplayData, QrResponseData } from './types/qr';\n\nexport type { ChainForFingerprint } from './types/fingerprint';\nexport { CHAIN_FINGERPRINT_PATHS, deriveDeviceFingerprint } from './types/fingerprint';\n\nexport type {\n IHardwareWallet,\n IUiHandler,\n PassphraseResponse,\n ChainCapability,\n DeviceEvent,\n UiRequestEvent,\n SdkEvent,\n HardwareEvent,\n HardwareEventMap,\n DeviceEventListener,\n} from './types/wallet';\n\nexport { DEVICE_EVENT, DEVICE } from './events/device';\nexport { UI_EVENT, UI_REQUEST, UI_RESPONSE } from './events/ui-request';\nexport { SDK } from './events/sdk';\n\nexport type {\n DeviceDescriptor,\n DeviceConnectEvent,\n DeviceDisconnectEvent,\n DeviceChangeEvent,\n} from './types/transport';\n\nexport { DeviceJobQueue } from './utils/DeviceJobQueue';\nexport type {\n Interruptibility,\n PreemptionDecision,\n JobOptions,\n ActiveJobInfo,\n PreemptionEvent,\n} from './utils/DeviceJobQueue';\nexport type { IUiBridge } from './types/ui-bridge';\n\nexport type {\n ConnectorDevice,\n ConnectorSession,\n ConnectorEventType,\n ConnectorEventMap,\n IConnector,\n IDesktopHardwareBridge,\n} from './types/connector';\nexport { createDesktopBridgeConnector, EConnectorInteraction } from './types/connector';\n\nexport { TypedEventEmitter } from './utils/TypedEventEmitter';\nexport { compareSemver } from './utils/semver';\n","export enum HardwareErrorCode {\n UnknownError = 0,\n DeviceNotFound = 1,\n DeviceDisconnected = 2,\n UserRejected = 3,\n DeviceBusy = 4,\n FirmwareUpdateRequired = 5,\n AppNotOpen = 6,\n InvalidParams = 7,\n TransportError = 8,\n OperationTimeout = 9,\n MethodNotSupported = 10,\n\n // PIN / Passphrase\n PinInvalid = 5520,\n PinCancelled = 5521,\n PassphraseRejected = 5522,\n\n // Device state\n DeviceLocked = 5530,\n DeviceNotInitialized = 5531,\n DeviceInBootloader = 5532,\n FirmwareTooOld = 5533,\n\n // Ledger specific\n WrongApp = 5540,\n\n // Device identity\n DeviceMismatch = 5560,\n\n // Transport\n BridgeNotFound = 5550,\n TransportNotAvailable = 5551,\n}\n","import { HardwareErrorCode } from './errors';\n\nexport interface Success<T> {\n success: true;\n payload: T;\n}\n\nexport interface Failure {\n success: false;\n payload: {\n error: string;\n code: HardwareErrorCode;\n };\n}\n\nexport type Response<T> = Success<T> | Failure;\n\nexport function success<T>(payload: T): Success<T> {\n return { success: true, payload };\n}\n\nexport function failure(code: HardwareErrorCode, error: string): Failure {\n return { success: false, payload: { error, code } };\n}\n","/**\n * Chain fingerprint utilities for device identity verification.\n *\n * Ledger devices have ephemeral IDs that change every session.\n * To verify that the same seed/device is connected, we derive an address\n * at a fixed path (account 0, index 0) and hash it into a stable \"chain fingerprint\".\n */\n\n/**\n * Fixed derivation paths used to generate chain fingerprints.\n * Uses standard index 0 — Ledger firmware shows device confirmation for\n * non-standard paths (e.g., index=100), which would interrupt wallet creation.\n * The address is hashed into a 16-char fingerprint, not exposed directly.\n * - EVM: cointype 60 (Ledger ETH App only supports 60)\n * - BTC: cointype 1 (testnet)\n * - SOL: cointype 501, standard 3-level hardened\n */\nexport const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string> = {\n evm: \"m/44'/60'/0'/0/0\",\n // BTC: account-level path (3 levels), mainnet cointype 0.\n // Cointype 1 (testnet) is rejected by some Ledger BTC App configurations.\n btc: \"m/44'/0'/0'\",\n sol: \"m/44'/501'/0'\",\n tron: \"m/44'/195'/0'/0/0\",\n};\n\nexport type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';\n\n/**\n * Hash an address string into a 16-character hex fingerprint.\n *\n * Uses a simple non-cryptographic hash (FNV-1a based) to avoid\n * pulling in a SHA-256 dependency. This is NOT used for security —\n * only for device identity matching.\n */\nexport function deriveDeviceFingerprint(address: string): string {\n // FNV-1a 64-bit constants (split into two 32-bit halves for JS)\n let h1 = 0x811c9dc5;\n let h2 = 0x01000193;\n\n for (let i = 0; i < address.length; i++) {\n const c = address.charCodeAt(i);\n h1 = Math.imul(h1 ^ c, h2);\n h2 = Math.imul(h2 ^ (c >>> 4), 0x01000193);\n }\n\n // Mix the two halves for better distribution\n h1 = Math.imul(h1 ^ (h1 >>> 16), 0x45d9f3b);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 0x45d9f3b);\n\n const hex1 = (h1 >>> 0).toString(16).padStart(8, '0');\n const hex2 = (h2 >>> 0).toString(16).padStart(8, '0');\n\n return `${hex1}${hex2}`;\n}\n","export const DEVICE_EVENT = 'DEVICE_EVENT';\n\n/** Events originating from the hardware device. */\nexport const DEVICE = {\n CONNECT: 'device-connect',\n DISCONNECT: 'device-disconnect',\n CHANGED: 'device-changed',\n ACQUIRE: 'device-acquire',\n RELEASE: 'device-release',\n FEATURES: 'features',\n SUPPORT_FEATURES: 'support_features',\n} as const;\n","export const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request-passphrase-on-device',\n REQUEST_BUTTON: 'ui-request-button',\n REQUEST_QR_DISPLAY: 'ui-request-qr-display',\n REQUEST_QR_SCAN: 'ui-request-qr-scan',\n REQUEST_DEVICE_PERMISSION: 'ui-request-device-permission',\n REQUEST_SELECT_DEVICE: 'ui-request-select-device',\n CLOSE_UI_WINDOW: 'ui-close',\n DEVICE_PROGRESS: 'ui-device_progress',\n FIRMWARE_PROGRESS: 'ui-firmware-progress',\n FIRMWARE_TIP: 'ui-firmware-tip',\n} as const;\n\nexport const UI_RESPONSE = {\n RECEIVE_PIN: 'receive-pin',\n RECEIVE_PASSPHRASE: 'receive-passphrase',\n RECEIVE_PASSPHRASE_ON_DEVICE: 'receive-passphrase-on-device',\n RECEIVE_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n CANCEL: 'cancel',\n} as const;\n","/** Events generated by SDK internal detection (not from hardware directly). */\nexport const SDK = {\n DEVICE_STUCK: 'device-stuck',\n DEVICE_UNRESPONSIVE: 'device-unresponsive',\n DEVICE_RECOVERED: 'device-recovered',\n DEVICE_INTERACTION: 'device-interaction',\n} as const;\n","/**\n * Per-device serial job queue with preemption support and stuck recovery.\n * Ensures that only one operation runs at a time per device, with intelligent\n * handling of conflicting operations.\n */\n\nexport type Interruptibility = 'none' | 'safe' | 'confirm';\n\nexport type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';\n\nexport interface JobOptions {\n interruptibility?: Interruptibility;\n label?: string;\n}\n\nexport interface ActiveJobInfo {\n label?: string;\n interruptibility: Interruptibility;\n startedAt: number;\n}\n\nexport interface PreemptionEvent {\n deviceId: string;\n currentJob: ActiveJobInfo;\n newJob: { label?: string; interruptibility: Interruptibility };\n}\n\ninterface ActiveJob {\n options: Required<Pick<JobOptions, 'interruptibility'>> & Pick<JobOptions, 'label'>;\n abortController: AbortController;\n startedAt: number;\n}\n\nexport class DeviceJobQueue {\n private readonly _queues = new Map<string, Promise<unknown>>();\n private readonly _active = new Map<string, ActiveJob>();\n\n /**\n * Called when a new job conflicts with an active 'confirm'-level job.\n * UI should show a dialog and return the user's decision.\n * If not set, defaults to 'wait' (queue behind current job).\n */\n onPreemptionRequest?: (event: PreemptionEvent) => Promise<PreemptionDecision>;\n\n /**\n * Enqueue a job for a specific device.\n * If a job is already running for this device, behavior depends on interruptibility:\n * - 'none': new job queues silently (no preemption possible)\n * - 'safe': current job is auto-cancelled, new job runs immediately after\n * - 'confirm': onPreemptionRequest is called to ask user\n */\n async enqueue<T>(\n deviceId: string,\n job: (signal: AbortSignal) => Promise<T>,\n options: JobOptions = {},\n ): Promise<T> {\n const interruptibility = options.interruptibility ?? 'confirm';\n const active = this._active.get(deviceId);\n\n if (active) {\n switch (active.options.interruptibility) {\n case 'none':\n // Cannot interrupt, just queue behind\n break;\n case 'safe':\n // Auto-cancel current safe operation\n active.abortController.abort(new Error('Preempted by new operation'));\n break;\n case 'confirm': {\n if (this.onPreemptionRequest) {\n const decision = await this.onPreemptionRequest({\n deviceId,\n currentJob: {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n },\n newJob: {\n label: options.label,\n interruptibility,\n },\n });\n switch (decision) {\n case 'cancel-current':\n active.abortController.abort(new Error('Cancelled by user via preemption'));\n break;\n case 'reject-new':\n throw Object.assign(\n new Error(`Device busy: ${active.options.label ?? 'unknown operation'}`),\n { hardwareErrorCode: 'DEVICE_BUSY' },\n );\n case 'wait':\n break;\n }\n }\n break;\n }\n }\n }\n\n const ac = new AbortController();\n const prev = this._queues.get(deviceId) ?? Promise.resolve();\n\n const next = prev.catch(() => {}).then(async () => {\n this._active.set(deviceId, {\n options: { interruptibility, label: options.label },\n abortController: ac,\n startedAt: Date.now(),\n });\n try {\n return await job(ac.signal);\n } finally {\n this._active.delete(deviceId);\n }\n });\n\n const tail = next.catch(() => {});\n this._queues.set(deviceId, tail);\n tail.then(() => {\n if (this._queues.get(deviceId) === tail) {\n this._queues.delete(deviceId);\n }\n });\n return next;\n }\n\n /** Manually cancel the active job on a device. Returns false if job is non-interruptible. */\n cancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n if (active.options.interruptibility === 'none') return false;\n active.abortController.abort(new Error('Manually cancelled'));\n return true;\n }\n\n /** Force cancel regardless of interruptibility. Use for device stuck recovery. */\n forceCancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n active.abortController.abort(new Error('Force cancelled for recovery'));\n return true;\n }\n\n /** Get info about the currently active job for a device, or null if idle. */\n getActiveJob(deviceId: string): ActiveJobInfo | null {\n const active = this._active.get(deviceId);\n if (!active) return null;\n return {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n };\n }\n\n clear(): void {\n // Abort all active jobs\n for (const active of this._active.values()) {\n active.abortController.abort(new Error('Queue cleared'));\n }\n this._active.clear();\n this._queues.clear();\n }\n}\n","import type { DeviceCapabilities, DeviceInfo, VendorType } from './device';\n\n// =====================================================================\n// Connector types — transport-level abstraction for device communication\n// =====================================================================\n\n/**\n * Minimal device info returned during discovery (searchDevices).\n * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.\n */\nexport interface ConnectorDevice {\n connectId: string;\n deviceId: string;\n name: string;\n model?: string;\n\n /** Device capabilities — available from scan time */\n capabilities?: DeviceCapabilities;\n}\n\nexport interface ConnectorSession {\n sessionId: string;\n deviceInfo: DeviceInfo;\n}\n\nexport type ConnectorEventType =\n | 'device-connect'\n | 'device-disconnect'\n | 'ui-request'\n | 'ui-event';\n\n/**\n * Interaction event types emitted via 'ui-event'.\n * These map to user-facing prompts (confirm on device, open app, etc.).\n */\nexport enum EConnectorInteraction {\n /** Device requires user to open a specific app */\n ConfirmOpenApp = 'confirm-open-app',\n /** Device requires user to unlock */\n UnlockDevice = 'unlock-device',\n /** Device needs user to confirm on device (sign, verify, etc.) */\n ConfirmOnDevice = 'confirm-on-device',\n /** Previous interaction completed — clear UI prompt */\n InteractionComplete = 'interaction-complete',\n}\n\nexport interface ConnectorEventMap {\n 'device-connect': { device: ConnectorDevice };\n 'device-disconnect': { connectId: string };\n 'ui-request': { type: string; payload?: unknown };\n 'ui-event': { type: string; payload?: unknown };\n}\n\nexport interface IConnector {\n searchDevices(): Promise<ConnectorDevice[]>;\n connect(deviceId?: string): Promise<ConnectorSession>;\n disconnect(sessionId: string): Promise<void>;\n call(sessionId: string, method: string, params: unknown): Promise<unknown>;\n cancel(sessionId: string): Promise<void>;\n\n /** Send a UI response (e.g. PIN, passphrase) to the device. */\n uiResponse(response: { type: string; payload: unknown }): void;\n\n on<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n off<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n\n reset(): void;\n}\n\n// =====================================================================\n// Desktop IPC bridge — generic interface for main-process hardware access\n// =====================================================================\n\nexport interface IDesktopHardwareBridge {\n searchDevices(params: { vendor: VendorType }): Promise<ConnectorDevice[]>;\n connect(params: {\n vendor: VendorType;\n deviceId?: string;\n }): Promise<ConnectorSession>;\n disconnect(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n call(params: {\n vendor: VendorType;\n sessionId: string;\n method: string;\n callParams: unknown;\n }): Promise<unknown>;\n cancel(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n uiResponse(params: {\n vendor: VendorType;\n response: { type: string; payload: unknown };\n }): void;\n reset(params: { vendor: VendorType }): void;\n\n /** Register an event handler for connector events forwarded from the main process. */\n onEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n\n /** Unregister a previously registered event handler. */\n offEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n}\n\n/**\n * Create an IConnector from a desktop IPC bridge + vendor name.\n * Events are forwarded via bridge.onEvent/offEvent.\n */\nexport function createDesktopBridgeConnector(\n vendor: VendorType,\n bridge: IDesktopHardwareBridge,\n): IConnector {\n // Map from typed IConnector handlers to the bridge handler so we can\n // unregister them correctly via off().\n const handlerMap = new Map<\n (data: ConnectorEventMap[ConnectorEventType]) => void,\n (event: { type: ConnectorEventType; data: unknown }) => void\n >();\n\n return {\n searchDevices: () => bridge.searchDevices({ vendor }),\n connect: (deviceId) => bridge.connect({ vendor, deviceId }),\n disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),\n call: (sessionId, method, callParams) =>\n bridge.call({ vendor, sessionId, method, callParams }),\n cancel: (sessionId) => bridge.cancel({ vendor, sessionId }),\n uiResponse: (response) => bridge.uiResponse({ vendor, response }),\n on: (event, handler) => {\n const bridgeHandler = (e: { type: ConnectorEventType; data: unknown }) => {\n if (e.type === event) {\n handler(e.data as ConnectorEventMap[typeof event]);\n }\n };\n handlerMap.set(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n bridgeHandler,\n );\n bridge.onEvent({ vendor }, bridgeHandler);\n },\n off: (_event, handler) => {\n const bridgeHandler = handlerMap.get(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n if (bridgeHandler) {\n bridge.offEvent({ vendor }, bridgeHandler);\n handlerMap.delete(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n }\n },\n reset: () => bridge.reset({ vendor }),\n };\n}\n","/**\n * Minimal typed event emitter using Map<string, Set<listener>>.\n * Each adapter uses this for device events (connect, disconnect, pin, etc.).\n *\n * TMap is a record mapping event name strings to their payload types.\n * Example:\n * type MyEvents = { 'connect': { id: string }; 'disconnect': { id: string } };\n * const emitter = new TypedEventEmitter<MyEvents>();\n * emitter.on('connect', (data) => { data.id }); // data is { id: string }\n *\n * For backward compatibility, TMap defaults to Record<string, any> so that\n * existing code using `new TypedEventEmitter<SomeUnionType>()` still compiles.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class TypedEventEmitter<TMap extends Record<string, any> = Record<string, any>> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly _listeners = new Map<string, Set<(event: any) => void>>();\n\n on<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n on(event: string, listener: (event: any) => void): void;\n on(event: string, listener: (event: any) => void): void {\n let set = this._listeners.get(event);\n if (!set) {\n set = new Set();\n this._listeners.set(event, set);\n }\n set.add(listener);\n }\n\n off<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n off(event: string, listener: (event: any) => void): void;\n off(event: string, listener: (event: any) => void): void {\n const set = this._listeners.get(event);\n if (set) {\n set.delete(listener);\n if (set.size === 0) this._listeners.delete(event);\n }\n }\n\n emit<K extends keyof TMap & string>(event: K, data: TMap[K]): void;\n emit(event: string, data: unknown): void;\n emit(event: string, data: unknown): void {\n const set = this._listeners.get(event);\n if (set) {\n for (const listener of set) listener(data);\n }\n }\n\n removeAllListeners(): void {\n this._listeners.clear();\n }\n}\n","/**\n * Compare two semver strings (e.g. \"2.1.0\" vs \"2.3.1\").\n * Returns -1 if a < b, 0 if equal, 1 if a > b.\n */\nexport function compareSemver(a: string, b: string): number {\n const pa = a.split('.').map(Number);\n const pb = b.split('.').map(Number);\n for (let i = 0; i < 3; i++) {\n const va = pa[i] ?? 0;\n const vb = pb[i] ?? 0;\n if (va < vb) return -1;\n if (va > vb) return 1;\n }\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,sCAAA,kBAAe,KAAf;AACA,EAAAA,sCAAA,oBAAiB,KAAjB;AACA,EAAAA,sCAAA,wBAAqB,KAArB;AACA,EAAAA,sCAAA,kBAAe,KAAf;AACA,EAAAA,sCAAA,gBAAa,KAAb;AACA,EAAAA,sCAAA,4BAAyB,KAAzB;AACA,EAAAA,sCAAA,gBAA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AAQ;AAAA,EAClB;AAAA,EAIA,IAAI,OAAe,UAAsC;AACvD,UAAM,MAAM,KAAK,WAAW,IAAI,KAAK;AACrC,QAAI,KAAK;AACP,UAAI,OAAO,QAAQ;AACnB,UAAI,IAAI,SAAS,EAAG,MAAK,WAAW,OAAO,KAAK;AAAA,IAClD;AAAA,EACF;AAAA,EAIA,KAAK,OAAe,MAAqB;AACvC,UAAM,MAAM,KAAK,WAAW,IAAI,KAAK;AACrC,QAAI,KAAK;AACP,iBAAW,YAAY,IAAK,UAAS,IAAI;AAAA,IAC3C;AAAA,EACF;AAAA,EAEA,qBAA2B;AACzB,SAAK,WAAW,MAAM;AAAA,EACxB;AACF;;;AC/CO,SAAS,cAAc,GAAW,GAAmB;AAC1D,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,QAAI,KAAK,GAAI,QAAO;AACpB,QAAI,KAAK,GAAI,QAAO;AAAA,EACtB;AACA,SAAO;AACT;","names":["HardwareErrorCode","EConnectorInteraction"]}
|
package/dist/index.mjs
CHANGED
|
@@ -216,6 +216,13 @@ var DeviceJobQueue = class {
|
|
|
216
216
|
};
|
|
217
217
|
|
|
218
218
|
// src/types/connector.ts
|
|
219
|
+
var EConnectorInteraction = /* @__PURE__ */ ((EConnectorInteraction2) => {
|
|
220
|
+
EConnectorInteraction2["ConfirmOpenApp"] = "confirm-open-app";
|
|
221
|
+
EConnectorInteraction2["UnlockDevice"] = "unlock-device";
|
|
222
|
+
EConnectorInteraction2["ConfirmOnDevice"] = "confirm-on-device";
|
|
223
|
+
EConnectorInteraction2["InteractionComplete"] = "interaction-complete";
|
|
224
|
+
return EConnectorInteraction2;
|
|
225
|
+
})(EConnectorInteraction || {});
|
|
219
226
|
function createDesktopBridgeConnector(vendor, bridge) {
|
|
220
227
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
221
228
|
return {
|
|
@@ -301,6 +308,7 @@ export {
|
|
|
301
308
|
DEVICE,
|
|
302
309
|
DEVICE_EVENT,
|
|
303
310
|
DeviceJobQueue,
|
|
311
|
+
EConnectorInteraction,
|
|
304
312
|
HardwareErrorCode,
|
|
305
313
|
SDK,
|
|
306
314
|
TypedEventEmitter,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/errors.ts","../src/types/response.ts","../src/types/fingerprint.ts","../src/events/device.ts","../src/events/ui-request.ts","../src/events/sdk.ts","../src/utils/DeviceJobQueue.ts","../src/types/connector.ts","../src/utils/TypedEventEmitter.ts","../src/utils/semver.ts"],"sourcesContent":["export enum HardwareErrorCode {\n UnknownError = 0,\n DeviceNotFound = 1,\n DeviceDisconnected = 2,\n UserRejected = 3,\n DeviceBusy = 4,\n FirmwareUpdateRequired = 5,\n AppNotOpen = 6,\n InvalidParams = 7,\n TransportError = 8,\n OperationTimeout = 9,\n MethodNotSupported = 10,\n\n // PIN / Passphrase\n PinInvalid = 5520,\n PinCancelled = 5521,\n PassphraseRejected = 5522,\n\n // Device state\n DeviceLocked = 5530,\n DeviceNotInitialized = 5531,\n DeviceInBootloader = 5532,\n FirmwareTooOld = 5533,\n\n // Ledger specific\n WrongApp = 5540,\n\n // Device identity\n DeviceMismatch = 5560,\n\n // Transport\n BridgeNotFound = 5550,\n TransportNotAvailable = 5551,\n}\n","import { HardwareErrorCode } from './errors';\n\nexport interface Success<T> {\n success: true;\n payload: T;\n}\n\nexport interface Failure {\n success: false;\n payload: {\n error: string;\n code: HardwareErrorCode;\n };\n}\n\nexport type Response<T> = Success<T> | Failure;\n\nexport function success<T>(payload: T): Success<T> {\n return { success: true, payload };\n}\n\nexport function failure(code: HardwareErrorCode, error: string): Failure {\n return { success: false, payload: { error, code } };\n}\n","/**\n * Chain fingerprint utilities for device identity verification.\n *\n * Ledger devices have ephemeral IDs that change every session.\n * To verify that the same seed/device is connected, we derive an address\n * at a fixed path (account 0, index 0) and hash it into a stable \"chain fingerprint\".\n */\n\n/**\n * Fixed derivation paths used to generate chain fingerprints.\n * Uses standard index 0 — Ledger firmware shows device confirmation for\n * non-standard paths (e.g., index=100), which would interrupt wallet creation.\n * The address is hashed into a 16-char fingerprint, not exposed directly.\n * - EVM: cointype 60 (Ledger ETH App only supports 60)\n * - BTC: cointype 1 (testnet)\n * - SOL: cointype 501, standard 3-level hardened\n */\nexport const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string> = {\n evm: \"m/44'/60'/0'/0/0\",\n // BTC: account-level path (3 levels), mainnet cointype 0.\n // Cointype 1 (testnet) is rejected by some Ledger BTC App configurations.\n btc: \"m/44'/0'/0'\",\n sol: \"m/44'/501'/0'\",\n tron: \"m/44'/195'/0'/0/0\",\n};\n\nexport type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';\n\n/**\n * Hash an address string into a 16-character hex fingerprint.\n *\n * Uses a simple non-cryptographic hash (FNV-1a based) to avoid\n * pulling in a SHA-256 dependency. This is NOT used for security —\n * only for device identity matching.\n */\nexport function deriveDeviceFingerprint(address: string): string {\n // FNV-1a 64-bit constants (split into two 32-bit halves for JS)\n let h1 = 0x811c9dc5;\n let h2 = 0x01000193;\n\n for (let i = 0; i < address.length; i++) {\n const c = address.charCodeAt(i);\n h1 = Math.imul(h1 ^ c, h2);\n h2 = Math.imul(h2 ^ (c >>> 4), 0x01000193);\n }\n\n // Mix the two halves for better distribution\n h1 = Math.imul(h1 ^ (h1 >>> 16), 0x45d9f3b);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 0x45d9f3b);\n\n const hex1 = (h1 >>> 0).toString(16).padStart(8, '0');\n const hex2 = (h2 >>> 0).toString(16).padStart(8, '0');\n\n return `${hex1}${hex2}`;\n}\n","export const DEVICE_EVENT = 'DEVICE_EVENT';\n\n/** Events originating from the hardware device. */\nexport const DEVICE = {\n CONNECT: 'device-connect',\n DISCONNECT: 'device-disconnect',\n CHANGED: 'device-changed',\n ACQUIRE: 'device-acquire',\n RELEASE: 'device-release',\n FEATURES: 'features',\n SUPPORT_FEATURES: 'support_features',\n} as const;\n","export const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request-passphrase-on-device',\n REQUEST_BUTTON: 'ui-request-button',\n REQUEST_QR_DISPLAY: 'ui-request-qr-display',\n REQUEST_QR_SCAN: 'ui-request-qr-scan',\n REQUEST_DEVICE_PERMISSION: 'ui-request-device-permission',\n REQUEST_SELECT_DEVICE: 'ui-request-select-device',\n CLOSE_UI_WINDOW: 'ui-close',\n DEVICE_PROGRESS: 'ui-device_progress',\n FIRMWARE_PROGRESS: 'ui-firmware-progress',\n FIRMWARE_TIP: 'ui-firmware-tip',\n} as const;\n\nexport const UI_RESPONSE = {\n RECEIVE_PIN: 'receive-pin',\n RECEIVE_PASSPHRASE: 'receive-passphrase',\n RECEIVE_PASSPHRASE_ON_DEVICE: 'receive-passphrase-on-device',\n RECEIVE_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n CANCEL: 'cancel',\n} as const;\n","/** Events generated by SDK internal detection (not from hardware directly). */\nexport const SDK = {\n DEVICE_STUCK: 'device-stuck',\n DEVICE_UNRESPONSIVE: 'device-unresponsive',\n DEVICE_RECOVERED: 'device-recovered',\n DEVICE_INTERACTION: 'device-interaction',\n} as const;\n","/**\n * Per-device serial job queue with preemption support and stuck recovery.\n * Ensures that only one operation runs at a time per device, with intelligent\n * handling of conflicting operations.\n */\n\nexport type Interruptibility = 'none' | 'safe' | 'confirm';\n\nexport type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';\n\nexport interface JobOptions {\n interruptibility?: Interruptibility;\n label?: string;\n}\n\nexport interface ActiveJobInfo {\n label?: string;\n interruptibility: Interruptibility;\n startedAt: number;\n}\n\nexport interface PreemptionEvent {\n deviceId: string;\n currentJob: ActiveJobInfo;\n newJob: { label?: string; interruptibility: Interruptibility };\n}\n\ninterface ActiveJob {\n options: Required<Pick<JobOptions, 'interruptibility'>> & Pick<JobOptions, 'label'>;\n abortController: AbortController;\n startedAt: number;\n}\n\nexport class DeviceJobQueue {\n private readonly _queues = new Map<string, Promise<unknown>>();\n private readonly _active = new Map<string, ActiveJob>();\n\n /**\n * Called when a new job conflicts with an active 'confirm'-level job.\n * UI should show a dialog and return the user's decision.\n * If not set, defaults to 'wait' (queue behind current job).\n */\n onPreemptionRequest?: (event: PreemptionEvent) => Promise<PreemptionDecision>;\n\n /**\n * Enqueue a job for a specific device.\n * If a job is already running for this device, behavior depends on interruptibility:\n * - 'none': new job queues silently (no preemption possible)\n * - 'safe': current job is auto-cancelled, new job runs immediately after\n * - 'confirm': onPreemptionRequest is called to ask user\n */\n async enqueue<T>(\n deviceId: string,\n job: (signal: AbortSignal) => Promise<T>,\n options: JobOptions = {},\n ): Promise<T> {\n const interruptibility = options.interruptibility ?? 'confirm';\n const active = this._active.get(deviceId);\n\n if (active) {\n switch (active.options.interruptibility) {\n case 'none':\n // Cannot interrupt, just queue behind\n break;\n case 'safe':\n // Auto-cancel current safe operation\n active.abortController.abort(new Error('Preempted by new operation'));\n break;\n case 'confirm': {\n if (this.onPreemptionRequest) {\n const decision = await this.onPreemptionRequest({\n deviceId,\n currentJob: {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n },\n newJob: {\n label: options.label,\n interruptibility,\n },\n });\n switch (decision) {\n case 'cancel-current':\n active.abortController.abort(new Error('Cancelled by user via preemption'));\n break;\n case 'reject-new':\n throw Object.assign(\n new Error(`Device busy: ${active.options.label ?? 'unknown operation'}`),\n { hardwareErrorCode: 'DEVICE_BUSY' },\n );\n case 'wait':\n break;\n }\n }\n break;\n }\n }\n }\n\n const ac = new AbortController();\n const prev = this._queues.get(deviceId) ?? Promise.resolve();\n\n const next = prev.catch(() => {}).then(async () => {\n this._active.set(deviceId, {\n options: { interruptibility, label: options.label },\n abortController: ac,\n startedAt: Date.now(),\n });\n try {\n return await job(ac.signal);\n } finally {\n this._active.delete(deviceId);\n }\n });\n\n const tail = next.catch(() => {});\n this._queues.set(deviceId, tail);\n tail.then(() => {\n if (this._queues.get(deviceId) === tail) {\n this._queues.delete(deviceId);\n }\n });\n return next;\n }\n\n /** Manually cancel the active job on a device. Returns false if job is non-interruptible. */\n cancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n if (active.options.interruptibility === 'none') return false;\n active.abortController.abort(new Error('Manually cancelled'));\n return true;\n }\n\n /** Force cancel regardless of interruptibility. Use for device stuck recovery. */\n forceCancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n active.abortController.abort(new Error('Force cancelled for recovery'));\n return true;\n }\n\n /** Get info about the currently active job for a device, or null if idle. */\n getActiveJob(deviceId: string): ActiveJobInfo | null {\n const active = this._active.get(deviceId);\n if (!active) return null;\n return {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n };\n }\n\n clear(): void {\n // Abort all active jobs\n for (const active of this._active.values()) {\n active.abortController.abort(new Error('Queue cleared'));\n }\n this._active.clear();\n this._queues.clear();\n }\n}\n","import type { DeviceCapabilities, DeviceInfo, VendorType } from './device';\n\n// =====================================================================\n// Connector types — transport-level abstraction for device communication\n// =====================================================================\n\n/**\n * Minimal device info returned during discovery (searchDevices).\n * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.\n */\nexport interface ConnectorDevice {\n connectId: string;\n deviceId: string;\n name: string;\n model?: string;\n\n /** Device capabilities — available from scan time */\n capabilities?: DeviceCapabilities;\n}\n\nexport interface ConnectorSession {\n sessionId: string;\n deviceInfo: DeviceInfo;\n}\n\nexport type ConnectorEventType =\n | 'device-connect'\n | 'device-disconnect'\n | 'ui-request'\n | 'ui-event';\n\nexport interface ConnectorEventMap {\n 'device-connect': { device: ConnectorDevice };\n 'device-disconnect': { connectId: string };\n 'ui-request': { type: string; payload?: unknown };\n 'ui-event': { type: string; payload?: unknown };\n}\n\nexport interface IConnector {\n searchDevices(): Promise<ConnectorDevice[]>;\n connect(deviceId?: string): Promise<ConnectorSession>;\n disconnect(sessionId: string): Promise<void>;\n call(sessionId: string, method: string, params: unknown): Promise<unknown>;\n cancel(sessionId: string): Promise<void>;\n\n /** Send a UI response (e.g. PIN, passphrase) to the device. */\n uiResponse(response: { type: string; payload: unknown }): void;\n\n on<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n off<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n\n reset(): void;\n}\n\n// =====================================================================\n// Desktop IPC bridge — generic interface for main-process hardware access\n// =====================================================================\n\nexport interface IDesktopHardwareBridge {\n searchDevices(params: { vendor: VendorType }): Promise<ConnectorDevice[]>;\n connect(params: {\n vendor: VendorType;\n deviceId?: string;\n }): Promise<ConnectorSession>;\n disconnect(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n call(params: {\n vendor: VendorType;\n sessionId: string;\n method: string;\n callParams: unknown;\n }): Promise<unknown>;\n cancel(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n uiResponse(params: {\n vendor: VendorType;\n response: { type: string; payload: unknown };\n }): void;\n reset(params: { vendor: VendorType }): void;\n\n /** Register an event handler for connector events forwarded from the main process. */\n onEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n\n /** Unregister a previously registered event handler. */\n offEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n}\n\n/**\n * Create an IConnector from a desktop IPC bridge + vendor name.\n * Events are forwarded via bridge.onEvent/offEvent.\n */\nexport function createDesktopBridgeConnector(\n vendor: VendorType,\n bridge: IDesktopHardwareBridge,\n): IConnector {\n // Map from typed IConnector handlers to the bridge handler so we can\n // unregister them correctly via off().\n const handlerMap = new Map<\n (data: ConnectorEventMap[ConnectorEventType]) => void,\n (event: { type: ConnectorEventType; data: unknown }) => void\n >();\n\n return {\n searchDevices: () => bridge.searchDevices({ vendor }),\n connect: (deviceId) => bridge.connect({ vendor, deviceId }),\n disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),\n call: (sessionId, method, callParams) =>\n bridge.call({ vendor, sessionId, method, callParams }),\n cancel: (sessionId) => bridge.cancel({ vendor, sessionId }),\n uiResponse: (response) => bridge.uiResponse({ vendor, response }),\n on: (event, handler) => {\n const bridgeHandler = (e: { type: ConnectorEventType; data: unknown }) => {\n if (e.type === event) {\n handler(e.data as ConnectorEventMap[typeof event]);\n }\n };\n handlerMap.set(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n bridgeHandler,\n );\n bridge.onEvent({ vendor }, bridgeHandler);\n },\n off: (_event, handler) => {\n const bridgeHandler = handlerMap.get(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n if (bridgeHandler) {\n bridge.offEvent({ vendor }, bridgeHandler);\n handlerMap.delete(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n }\n },\n reset: () => bridge.reset({ vendor }),\n };\n}\n","/**\n * Minimal typed event emitter using Map<string, Set<listener>>.\n * Each adapter uses this for device events (connect, disconnect, pin, etc.).\n *\n * TMap is a record mapping event name strings to their payload types.\n * Example:\n * type MyEvents = { 'connect': { id: string }; 'disconnect': { id: string } };\n * const emitter = new TypedEventEmitter<MyEvents>();\n * emitter.on('connect', (data) => { data.id }); // data is { id: string }\n *\n * For backward compatibility, TMap defaults to Record<string, any> so that\n * existing code using `new TypedEventEmitter<SomeUnionType>()` still compiles.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class TypedEventEmitter<TMap extends Record<string, any> = Record<string, any>> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly _listeners = new Map<string, Set<(event: any) => void>>();\n\n on<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n on(event: string, listener: (event: any) => void): void;\n on(event: string, listener: (event: any) => void): void {\n let set = this._listeners.get(event);\n if (!set) {\n set = new Set();\n this._listeners.set(event, set);\n }\n set.add(listener);\n }\n\n off<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n off(event: string, listener: (event: any) => void): void;\n off(event: string, listener: (event: any) => void): void {\n const set = this._listeners.get(event);\n if (set) {\n set.delete(listener);\n if (set.size === 0) this._listeners.delete(event);\n }\n }\n\n emit<K extends keyof TMap & string>(event: K, data: TMap[K]): void;\n emit(event: string, data: unknown): void;\n emit(event: string, data: unknown): void {\n const set = this._listeners.get(event);\n if (set) {\n for (const listener of set) listener(data);\n }\n }\n\n removeAllListeners(): void {\n this._listeners.clear();\n }\n}\n","/**\n * Compare two semver strings (e.g. \"2.1.0\" vs \"2.3.1\").\n * Returns -1 if a < b, 0 if equal, 1 if a > b.\n */\nexport function compareSemver(a: string, b: string): number {\n const pa = a.split('.').map(Number);\n const pb = b.split('.').map(Number);\n for (let i = 0; i < 3; i++) {\n const va = pa[i] ?? 0;\n const vb = pb[i] ?? 0;\n if (va < vb) return -1;\n if (va > vb) return 1;\n }\n return 0;\n}\n"],"mappings":";AAAO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,sCAAA,kBAAe,KAAf;AACA,EAAAA,sCAAA,oBAAiB,KAAjB;AACA,EAAAA,sCAAA,wBAAqB,KAArB;AACA,EAAAA,sCAAA,kBAAe,KAAf;AACA,EAAAA,sCAAA,gBAAa,KAAb;AACA,EAAAA,sCAAA,4BAAyB,KAAzB;AACA,EAAAA,sCAAA,gBAAa,KAAb;AACA,EAAAA,sCAAA,mBAAgB,KAAhB;AACA,EAAAA,sCAAA,oBAAiB,KAAjB;AACA,EAAA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K,WAAW,IAAI,KAAK;AACrC,QAAI,KAAK;AACP,iBAAW,YAAY,IAAK,UAAS,IAAI;AAAA,IAC3C;AAAA,EACF;AAAA,EAEA,qBAA2B;AACzB,SAAK,WAAW,MAAM;AAAA,EACxB;AACF;;;AC/CO,SAAS,cAAc,GAAW,GAAmB;AAC1D,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,QAAI,KAAK,GAAI,QAAO;AACpB,QAAI,KAAK,GAAI,QAAO;AAAA,EACtB;AACA,SAAO;AACT;","names":["HardwareErrorCode"]}
|
|
1
|
+
{"version":3,"sources":["../src/types/errors.ts","../src/types/response.ts","../src/types/fingerprint.ts","../src/events/device.ts","../src/events/ui-request.ts","../src/events/sdk.ts","../src/utils/DeviceJobQueue.ts","../src/types/connector.ts","../src/utils/TypedEventEmitter.ts","../src/utils/semver.ts"],"sourcesContent":["export enum HardwareErrorCode {\n UnknownError = 0,\n DeviceNotFound = 1,\n DeviceDisconnected = 2,\n UserRejected = 3,\n DeviceBusy = 4,\n FirmwareUpdateRequired = 5,\n AppNotOpen = 6,\n InvalidParams = 7,\n TransportError = 8,\n OperationTimeout = 9,\n MethodNotSupported = 10,\n\n // PIN / Passphrase\n PinInvalid = 5520,\n PinCancelled = 5521,\n PassphraseRejected = 5522,\n\n // Device state\n DeviceLocked = 5530,\n DeviceNotInitialized = 5531,\n DeviceInBootloader = 5532,\n FirmwareTooOld = 5533,\n\n // Ledger specific\n WrongApp = 5540,\n\n // Device identity\n DeviceMismatch = 5560,\n\n // Transport\n BridgeNotFound = 5550,\n TransportNotAvailable = 5551,\n}\n","import { HardwareErrorCode } from './errors';\n\nexport interface Success<T> {\n success: true;\n payload: T;\n}\n\nexport interface Failure {\n success: false;\n payload: {\n error: string;\n code: HardwareErrorCode;\n };\n}\n\nexport type Response<T> = Success<T> | Failure;\n\nexport function success<T>(payload: T): Success<T> {\n return { success: true, payload };\n}\n\nexport function failure(code: HardwareErrorCode, error: string): Failure {\n return { success: false, payload: { error, code } };\n}\n","/**\n * Chain fingerprint utilities for device identity verification.\n *\n * Ledger devices have ephemeral IDs that change every session.\n * To verify that the same seed/device is connected, we derive an address\n * at a fixed path (account 0, index 0) and hash it into a stable \"chain fingerprint\".\n */\n\n/**\n * Fixed derivation paths used to generate chain fingerprints.\n * Uses standard index 0 — Ledger firmware shows device confirmation for\n * non-standard paths (e.g., index=100), which would interrupt wallet creation.\n * The address is hashed into a 16-char fingerprint, not exposed directly.\n * - EVM: cointype 60 (Ledger ETH App only supports 60)\n * - BTC: cointype 1 (testnet)\n * - SOL: cointype 501, standard 3-level hardened\n */\nexport const CHAIN_FINGERPRINT_PATHS: Record<ChainForFingerprint, string> = {\n evm: \"m/44'/60'/0'/0/0\",\n // BTC: account-level path (3 levels), mainnet cointype 0.\n // Cointype 1 (testnet) is rejected by some Ledger BTC App configurations.\n btc: \"m/44'/0'/0'\",\n sol: \"m/44'/501'/0'\",\n tron: \"m/44'/195'/0'/0/0\",\n};\n\nexport type ChainForFingerprint = 'evm' | 'btc' | 'sol' | 'tron';\n\n/**\n * Hash an address string into a 16-character hex fingerprint.\n *\n * Uses a simple non-cryptographic hash (FNV-1a based) to avoid\n * pulling in a SHA-256 dependency. This is NOT used for security —\n * only for device identity matching.\n */\nexport function deriveDeviceFingerprint(address: string): string {\n // FNV-1a 64-bit constants (split into two 32-bit halves for JS)\n let h1 = 0x811c9dc5;\n let h2 = 0x01000193;\n\n for (let i = 0; i < address.length; i++) {\n const c = address.charCodeAt(i);\n h1 = Math.imul(h1 ^ c, h2);\n h2 = Math.imul(h2 ^ (c >>> 4), 0x01000193);\n }\n\n // Mix the two halves for better distribution\n h1 = Math.imul(h1 ^ (h1 >>> 16), 0x45d9f3b);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 0x45d9f3b);\n\n const hex1 = (h1 >>> 0).toString(16).padStart(8, '0');\n const hex2 = (h2 >>> 0).toString(16).padStart(8, '0');\n\n return `${hex1}${hex2}`;\n}\n","export const DEVICE_EVENT = 'DEVICE_EVENT';\n\n/** Events originating from the hardware device. */\nexport const DEVICE = {\n CONNECT: 'device-connect',\n DISCONNECT: 'device-disconnect',\n CHANGED: 'device-changed',\n ACQUIRE: 'device-acquire',\n RELEASE: 'device-release',\n FEATURES: 'features',\n SUPPORT_FEATURES: 'support_features',\n} as const;\n","export const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n REQUEST_PASSPHRASE_ON_DEVICE: 'ui-request-passphrase-on-device',\n REQUEST_BUTTON: 'ui-request-button',\n REQUEST_QR_DISPLAY: 'ui-request-qr-display',\n REQUEST_QR_SCAN: 'ui-request-qr-scan',\n REQUEST_DEVICE_PERMISSION: 'ui-request-device-permission',\n REQUEST_SELECT_DEVICE: 'ui-request-select-device',\n CLOSE_UI_WINDOW: 'ui-close',\n DEVICE_PROGRESS: 'ui-device_progress',\n FIRMWARE_PROGRESS: 'ui-firmware-progress',\n FIRMWARE_TIP: 'ui-firmware-tip',\n} as const;\n\nexport const UI_RESPONSE = {\n RECEIVE_PIN: 'receive-pin',\n RECEIVE_PASSPHRASE: 'receive-passphrase',\n RECEIVE_PASSPHRASE_ON_DEVICE: 'receive-passphrase-on-device',\n RECEIVE_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n CANCEL: 'cancel',\n} as const;\n","/** Events generated by SDK internal detection (not from hardware directly). */\nexport const SDK = {\n DEVICE_STUCK: 'device-stuck',\n DEVICE_UNRESPONSIVE: 'device-unresponsive',\n DEVICE_RECOVERED: 'device-recovered',\n DEVICE_INTERACTION: 'device-interaction',\n} as const;\n","/**\n * Per-device serial job queue with preemption support and stuck recovery.\n * Ensures that only one operation runs at a time per device, with intelligent\n * handling of conflicting operations.\n */\n\nexport type Interruptibility = 'none' | 'safe' | 'confirm';\n\nexport type PreemptionDecision = 'cancel-current' | 'wait' | 'reject-new';\n\nexport interface JobOptions {\n interruptibility?: Interruptibility;\n label?: string;\n}\n\nexport interface ActiveJobInfo {\n label?: string;\n interruptibility: Interruptibility;\n startedAt: number;\n}\n\nexport interface PreemptionEvent {\n deviceId: string;\n currentJob: ActiveJobInfo;\n newJob: { label?: string; interruptibility: Interruptibility };\n}\n\ninterface ActiveJob {\n options: Required<Pick<JobOptions, 'interruptibility'>> & Pick<JobOptions, 'label'>;\n abortController: AbortController;\n startedAt: number;\n}\n\nexport class DeviceJobQueue {\n private readonly _queues = new Map<string, Promise<unknown>>();\n private readonly _active = new Map<string, ActiveJob>();\n\n /**\n * Called when a new job conflicts with an active 'confirm'-level job.\n * UI should show a dialog and return the user's decision.\n * If not set, defaults to 'wait' (queue behind current job).\n */\n onPreemptionRequest?: (event: PreemptionEvent) => Promise<PreemptionDecision>;\n\n /**\n * Enqueue a job for a specific device.\n * If a job is already running for this device, behavior depends on interruptibility:\n * - 'none': new job queues silently (no preemption possible)\n * - 'safe': current job is auto-cancelled, new job runs immediately after\n * - 'confirm': onPreemptionRequest is called to ask user\n */\n async enqueue<T>(\n deviceId: string,\n job: (signal: AbortSignal) => Promise<T>,\n options: JobOptions = {},\n ): Promise<T> {\n const interruptibility = options.interruptibility ?? 'confirm';\n const active = this._active.get(deviceId);\n\n if (active) {\n switch (active.options.interruptibility) {\n case 'none':\n // Cannot interrupt, just queue behind\n break;\n case 'safe':\n // Auto-cancel current safe operation\n active.abortController.abort(new Error('Preempted by new operation'));\n break;\n case 'confirm': {\n if (this.onPreemptionRequest) {\n const decision = await this.onPreemptionRequest({\n deviceId,\n currentJob: {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n },\n newJob: {\n label: options.label,\n interruptibility,\n },\n });\n switch (decision) {\n case 'cancel-current':\n active.abortController.abort(new Error('Cancelled by user via preemption'));\n break;\n case 'reject-new':\n throw Object.assign(\n new Error(`Device busy: ${active.options.label ?? 'unknown operation'}`),\n { hardwareErrorCode: 'DEVICE_BUSY' },\n );\n case 'wait':\n break;\n }\n }\n break;\n }\n }\n }\n\n const ac = new AbortController();\n const prev = this._queues.get(deviceId) ?? Promise.resolve();\n\n const next = prev.catch(() => {}).then(async () => {\n this._active.set(deviceId, {\n options: { interruptibility, label: options.label },\n abortController: ac,\n startedAt: Date.now(),\n });\n try {\n return await job(ac.signal);\n } finally {\n this._active.delete(deviceId);\n }\n });\n\n const tail = next.catch(() => {});\n this._queues.set(deviceId, tail);\n tail.then(() => {\n if (this._queues.get(deviceId) === tail) {\n this._queues.delete(deviceId);\n }\n });\n return next;\n }\n\n /** Manually cancel the active job on a device. Returns false if job is non-interruptible. */\n cancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n if (active.options.interruptibility === 'none') return false;\n active.abortController.abort(new Error('Manually cancelled'));\n return true;\n }\n\n /** Force cancel regardless of interruptibility. Use for device stuck recovery. */\n forceCancelActive(deviceId: string): boolean {\n const active = this._active.get(deviceId);\n if (!active) return false;\n active.abortController.abort(new Error('Force cancelled for recovery'));\n return true;\n }\n\n /** Get info about the currently active job for a device, or null if idle. */\n getActiveJob(deviceId: string): ActiveJobInfo | null {\n const active = this._active.get(deviceId);\n if (!active) return null;\n return {\n label: active.options.label,\n interruptibility: active.options.interruptibility,\n startedAt: active.startedAt,\n };\n }\n\n clear(): void {\n // Abort all active jobs\n for (const active of this._active.values()) {\n active.abortController.abort(new Error('Queue cleared'));\n }\n this._active.clear();\n this._queues.clear();\n }\n}\n","import type { DeviceCapabilities, DeviceInfo, VendorType } from './device';\n\n// =====================================================================\n// Connector types — transport-level abstraction for device communication\n// =====================================================================\n\n/**\n * Minimal device info returned during discovery (searchDevices).\n * At scan time, full DeviceInfo fields like firmwareVersion are not yet available.\n */\nexport interface ConnectorDevice {\n connectId: string;\n deviceId: string;\n name: string;\n model?: string;\n\n /** Device capabilities — available from scan time */\n capabilities?: DeviceCapabilities;\n}\n\nexport interface ConnectorSession {\n sessionId: string;\n deviceInfo: DeviceInfo;\n}\n\nexport type ConnectorEventType =\n | 'device-connect'\n | 'device-disconnect'\n | 'ui-request'\n | 'ui-event';\n\n/**\n * Interaction event types emitted via 'ui-event'.\n * These map to user-facing prompts (confirm on device, open app, etc.).\n */\nexport enum EConnectorInteraction {\n /** Device requires user to open a specific app */\n ConfirmOpenApp = 'confirm-open-app',\n /** Device requires user to unlock */\n UnlockDevice = 'unlock-device',\n /** Device needs user to confirm on device (sign, verify, etc.) */\n ConfirmOnDevice = 'confirm-on-device',\n /** Previous interaction completed — clear UI prompt */\n InteractionComplete = 'interaction-complete',\n}\n\nexport interface ConnectorEventMap {\n 'device-connect': { device: ConnectorDevice };\n 'device-disconnect': { connectId: string };\n 'ui-request': { type: string; payload?: unknown };\n 'ui-event': { type: string; payload?: unknown };\n}\n\nexport interface IConnector {\n searchDevices(): Promise<ConnectorDevice[]>;\n connect(deviceId?: string): Promise<ConnectorSession>;\n disconnect(sessionId: string): Promise<void>;\n call(sessionId: string, method: string, params: unknown): Promise<unknown>;\n cancel(sessionId: string): Promise<void>;\n\n /** Send a UI response (e.g. PIN, passphrase) to the device. */\n uiResponse(response: { type: string; payload: unknown }): void;\n\n on<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n off<K extends ConnectorEventType>(\n event: K,\n handler: (data: ConnectorEventMap[K]) => void,\n ): void;\n\n reset(): void;\n}\n\n// =====================================================================\n// Desktop IPC bridge — generic interface for main-process hardware access\n// =====================================================================\n\nexport interface IDesktopHardwareBridge {\n searchDevices(params: { vendor: VendorType }): Promise<ConnectorDevice[]>;\n connect(params: {\n vendor: VendorType;\n deviceId?: string;\n }): Promise<ConnectorSession>;\n disconnect(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n call(params: {\n vendor: VendorType;\n sessionId: string;\n method: string;\n callParams: unknown;\n }): Promise<unknown>;\n cancel(params: { vendor: VendorType; sessionId: string }): Promise<void>;\n uiResponse(params: {\n vendor: VendorType;\n response: { type: string; payload: unknown };\n }): void;\n reset(params: { vendor: VendorType }): void;\n\n /** Register an event handler for connector events forwarded from the main process. */\n onEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n\n /** Unregister a previously registered event handler. */\n offEvent(\n params: { vendor: VendorType },\n handler: (event: { type: ConnectorEventType; data: unknown }) => void,\n ): void;\n}\n\n/**\n * Create an IConnector from a desktop IPC bridge + vendor name.\n * Events are forwarded via bridge.onEvent/offEvent.\n */\nexport function createDesktopBridgeConnector(\n vendor: VendorType,\n bridge: IDesktopHardwareBridge,\n): IConnector {\n // Map from typed IConnector handlers to the bridge handler so we can\n // unregister them correctly via off().\n const handlerMap = new Map<\n (data: ConnectorEventMap[ConnectorEventType]) => void,\n (event: { type: ConnectorEventType; data: unknown }) => void\n >();\n\n return {\n searchDevices: () => bridge.searchDevices({ vendor }),\n connect: (deviceId) => bridge.connect({ vendor, deviceId }),\n disconnect: (sessionId) => bridge.disconnect({ vendor, sessionId }),\n call: (sessionId, method, callParams) =>\n bridge.call({ vendor, sessionId, method, callParams }),\n cancel: (sessionId) => bridge.cancel({ vendor, sessionId }),\n uiResponse: (response) => bridge.uiResponse({ vendor, response }),\n on: (event, handler) => {\n const bridgeHandler = (e: { type: ConnectorEventType; data: unknown }) => {\n if (e.type === event) {\n handler(e.data as ConnectorEventMap[typeof event]);\n }\n };\n handlerMap.set(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n bridgeHandler,\n );\n bridge.onEvent({ vendor }, bridgeHandler);\n },\n off: (_event, handler) => {\n const bridgeHandler = handlerMap.get(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n if (bridgeHandler) {\n bridge.offEvent({ vendor }, bridgeHandler);\n handlerMap.delete(\n handler as (data: ConnectorEventMap[ConnectorEventType]) => void,\n );\n }\n },\n reset: () => bridge.reset({ vendor }),\n };\n}\n","/**\n * Minimal typed event emitter using Map<string, Set<listener>>.\n * Each adapter uses this for device events (connect, disconnect, pin, etc.).\n *\n * TMap is a record mapping event name strings to their payload types.\n * Example:\n * type MyEvents = { 'connect': { id: string }; 'disconnect': { id: string } };\n * const emitter = new TypedEventEmitter<MyEvents>();\n * emitter.on('connect', (data) => { data.id }); // data is { id: string }\n *\n * For backward compatibility, TMap defaults to Record<string, any> so that\n * existing code using `new TypedEventEmitter<SomeUnionType>()` still compiles.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class TypedEventEmitter<TMap extends Record<string, any> = Record<string, any>> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly _listeners = new Map<string, Set<(event: any) => void>>();\n\n on<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n on(event: string, listener: (event: any) => void): void;\n on(event: string, listener: (event: any) => void): void {\n let set = this._listeners.get(event);\n if (!set) {\n set = new Set();\n this._listeners.set(event, set);\n }\n set.add(listener);\n }\n\n off<K extends keyof TMap & string>(event: K, listener: (event: TMap[K]) => void): void;\n off(event: string, listener: (event: any) => void): void;\n off(event: string, listener: (event: any) => void): void {\n const set = this._listeners.get(event);\n if (set) {\n set.delete(listener);\n if (set.size === 0) this._listeners.delete(event);\n }\n }\n\n emit<K extends keyof TMap & string>(event: K, data: TMap[K]): void;\n emit(event: string, data: unknown): void;\n emit(event: string, data: unknown): void {\n const set = this._listeners.get(event);\n if (set) {\n for (const listener of set) listener(data);\n }\n }\n\n removeAllListeners(): void {\n this._listeners.clear();\n }\n}\n","/**\n * Compare two semver strings (e.g. \"2.1.0\" vs \"2.3.1\").\n * Returns -1 if a < b, 0 if equal, 1 if a > b.\n */\nexport function compareSemver(a: string, b: string): number {\n const pa = a.split('.').map(Number);\n const pb = b.split('.').map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