@onekeyfe/hwk-adapter-core 1.1.26-alpha.6 → 1.1.26-alpha.8
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 +80 -79
- package/dist/index.d.ts +80 -79
- package/dist/index.js +59 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,49 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HWK HardwareErrorCode — independent namespace from the legacy
|
|
3
|
+
* `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).
|
|
4
|
+
*
|
|
5
|
+
* All HWK codes are 5-digit (>= 10000) so the two tables never collide
|
|
6
|
+
* even if either side grows. Each sub-category gets a 100-slot block.
|
|
7
|
+
*
|
|
8
|
+
* 10000-10099 Generic / cross-cutting primitives
|
|
9
|
+
* 10100-10199 Device state
|
|
10
|
+
* 10200-10299 Firmware
|
|
11
|
+
* 10300-10399 Transport + OS-level permission
|
|
12
|
+
* 10400-10499 PIN / Passphrase
|
|
13
|
+
* 10500-10599 App lifecycle (wrong app, not open, too old)
|
|
14
|
+
* 10600-10999 RESERVED — future adapter-level categories
|
|
15
|
+
*
|
|
16
|
+
* 11000-11099 EVM APDU (reactive mapping)
|
|
17
|
+
* 11100-11199 Solana APDU
|
|
18
|
+
* 11200-11299 Tron APDU
|
|
19
|
+
* 11300-11399 BTC APDU
|
|
20
|
+
* 11400-11999 RESERVED — future chain APDU blocks (100 per chain)
|
|
21
|
+
*
|
|
22
|
+
* 12000-99999 RESERVED — future major categories
|
|
23
|
+
*/
|
|
1
24
|
declare enum HardwareErrorCode {
|
|
2
|
-
UnknownError =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
UnknownError = 10000,
|
|
26
|
+
UserRejected = 10001,
|
|
27
|
+
InvalidParams = 10002,
|
|
28
|
+
OperationTimeout = 10003,
|
|
29
|
+
MethodNotSupported = 10004,
|
|
30
|
+
DeviceNotFound = 10100,
|
|
31
|
+
DeviceDisconnected = 10101,
|
|
32
|
+
DeviceBusy = 10102,
|
|
33
|
+
DeviceLocked = 10103,
|
|
34
|
+
DeviceNotInitialized = 10104,
|
|
35
|
+
DeviceInBootloader = 10105,
|
|
36
|
+
DeviceMismatch = 10106,
|
|
37
|
+
FirmwareTooOld = 10200,
|
|
38
|
+
FirmwareUpdateRequired = 10201,
|
|
39
|
+
TransportError = 10300,
|
|
40
|
+
BridgeNotFound = 10301,
|
|
41
|
+
TransportNotAvailable = 10302,
|
|
42
|
+
/**
|
|
43
|
+
* OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
|
|
44
|
+
* unavailable, or dismissed. Consumers surface a single "please grant
|
|
45
|
+
* permission" toast and let the user retry manually.
|
|
46
|
+
*/
|
|
47
|
+
DevicePermissionDenied = 10303,
|
|
48
|
+
PinInvalid = 10400,
|
|
49
|
+
PinCancelled = 10401,
|
|
50
|
+
PassphraseRejected = 10402,
|
|
51
|
+
AppNotOpen = 10500,
|
|
52
|
+
WrongApp = 10501,
|
|
53
|
+
/** 0x911c Command code not supported — app predates current SDK. */
|
|
54
|
+
AppTooOld = 10502,
|
|
24
55
|
/** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
|
|
25
56
|
* user has not enabled Blind signing on the device. */
|
|
26
|
-
EvmBlindSigningRequired =
|
|
57
|
+
EvmBlindSigningRequired = 11000,
|
|
27
58
|
/** 0x6984 Plugin not installed */
|
|
28
|
-
EvmClearSignPluginMissing =
|
|
59
|
+
EvmClearSignPluginMissing = 11001,
|
|
29
60
|
/** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
|
|
30
|
-
EvmDataTooLarge =
|
|
61
|
+
EvmDataTooLarge = 11002,
|
|
31
62
|
/** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
|
|
32
|
-
EvmTxTypeNotSupported =
|
|
33
|
-
/** 0x911c Command code not supported — app predates current SDK */
|
|
34
|
-
AppTooOld = 7005,
|
|
63
|
+
EvmTxTypeNotSupported = 11003,
|
|
35
64
|
/** 0x6808 Blind signing disabled for this instruction. */
|
|
36
|
-
SolanaBlindSigningRequired =
|
|
65
|
+
SolanaBlindSigningRequired = 11100,
|
|
37
66
|
/** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
|
|
38
|
-
TronCustomContractRequired =
|
|
67
|
+
TronCustomContractRequired = 11200,
|
|
39
68
|
/** 0x6a8b Transactions Data setting disabled. */
|
|
40
|
-
TronDataSigningRequired =
|
|
69
|
+
TronDataSigningRequired = 11201,
|
|
41
70
|
/** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
|
|
42
|
-
TronSignByHashRequired =
|
|
71
|
+
TronSignByHashRequired = 11202,
|
|
43
72
|
/** 0xb008 Wallet policy HMAC mismatch or not registered. */
|
|
44
|
-
BtcWalletPolicyHmacMismatch =
|
|
73
|
+
BtcWalletPolicyHmacMismatch = 11300,
|
|
45
74
|
/** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
|
|
46
|
-
BtcUnexpectedState =
|
|
75
|
+
BtcUnexpectedState = 11301
|
|
47
76
|
}
|
|
48
77
|
|
|
49
78
|
interface Success<T> {
|
|
@@ -517,6 +546,7 @@ declare const UI_RESPONSE: {
|
|
|
517
546
|
readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
|
|
518
547
|
readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
|
|
519
548
|
readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
|
|
549
|
+
readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
|
|
520
550
|
readonly RECEIVE_PREEMPTION: "receive-preemption";
|
|
521
551
|
readonly CANCEL: "cancel";
|
|
522
552
|
};
|
|
@@ -546,6 +576,11 @@ type UiResponseEvent = {
|
|
|
546
576
|
payload: {
|
|
547
577
|
confirmed: boolean;
|
|
548
578
|
};
|
|
579
|
+
} | {
|
|
580
|
+
type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
|
|
581
|
+
payload: {
|
|
582
|
+
granted: boolean;
|
|
583
|
+
};
|
|
549
584
|
} | {
|
|
550
585
|
type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;
|
|
551
586
|
payload: {
|
|
@@ -616,7 +651,11 @@ type UiRequestEvent = {
|
|
|
616
651
|
};
|
|
617
652
|
} | {
|
|
618
653
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
619
|
-
payload:
|
|
654
|
+
payload: {
|
|
655
|
+
transportType: TransportType;
|
|
656
|
+
connectId?: string;
|
|
657
|
+
deviceId?: string;
|
|
658
|
+
};
|
|
620
659
|
} | {
|
|
621
660
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
622
661
|
payload: {
|
|
@@ -726,7 +765,11 @@ interface HardwareEventMap {
|
|
|
726
765
|
};
|
|
727
766
|
[UI_REQUEST.REQUEST_DEVICE_PERMISSION]: {
|
|
728
767
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
729
|
-
payload:
|
|
768
|
+
payload: {
|
|
769
|
+
transportType: TransportType;
|
|
770
|
+
connectId?: string;
|
|
771
|
+
deviceId?: string;
|
|
772
|
+
};
|
|
730
773
|
};
|
|
731
774
|
[UI_REQUEST.REQUEST_SELECT_DEVICE]: {
|
|
732
775
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
@@ -781,47 +824,6 @@ interface HardwareEventMap {
|
|
|
781
824
|
};
|
|
782
825
|
};
|
|
783
826
|
}
|
|
784
|
-
/**
|
|
785
|
-
* Same-process callbacks for prompts and OS-level permission.
|
|
786
|
-
* Cross-process flows use events + `uiResponse` + `UiRequestRegistry` instead.
|
|
787
|
-
*/
|
|
788
|
-
interface IUiHandler {
|
|
789
|
-
onPinRequest(device: DeviceInfo): Promise<string>;
|
|
790
|
-
onPassphraseRequest(device: DeviceInfo): Promise<string | PassphraseResponse>;
|
|
791
|
-
onQrDisplay(device: DeviceInfo, data: QrDisplayData): Promise<QrResponseData>;
|
|
792
|
-
/**
|
|
793
|
-
* Check if device access permission is already granted.
|
|
794
|
-
* Returns { granted, context? }.
|
|
795
|
-
* - granted: true → skip onDevicePermission
|
|
796
|
-
* - granted: false → adapter calls onDevicePermission with the context
|
|
797
|
-
* - context: consumer-defined data passed through to onDevicePermission
|
|
798
|
-
*
|
|
799
|
-
* When connectId/deviceId are undefined (searchDevices), check environment-level
|
|
800
|
-
* permissions (USB: any paired device exists; BLE: bluetooth on + location permission).
|
|
801
|
-
* When connectId/deviceId are provided (business methods), check device-level
|
|
802
|
-
* permissions (USB: target device authorized; BLE: bluetooth on + device connected).
|
|
803
|
-
*/
|
|
804
|
-
checkDevicePermission?(params: {
|
|
805
|
-
transportType: TransportType;
|
|
806
|
-
connectId?: string;
|
|
807
|
-
deviceId?: string;
|
|
808
|
-
}): Promise<{
|
|
809
|
-
granted: boolean;
|
|
810
|
-
context?: Record<string, unknown>;
|
|
811
|
-
}>;
|
|
812
|
-
/**
|
|
813
|
-
* Request device access permission from the user.
|
|
814
|
-
* Only called when checkDevicePermission returns granted: false (or is not set).
|
|
815
|
-
*
|
|
816
|
-
* The handler decides what to do based on transportType + context:
|
|
817
|
-
* - usb/hid: open pairing page or call requestWebUSBDevice
|
|
818
|
-
* - ble: enable bluetooth, request location permission, start scanning
|
|
819
|
-
*/
|
|
820
|
-
onDevicePermission(params: {
|
|
821
|
-
transportType: TransportType;
|
|
822
|
-
context?: Record<string, unknown>;
|
|
823
|
-
}): Promise<void>;
|
|
824
|
-
}
|
|
825
827
|
interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, ISolMethods, ITronMethods {
|
|
826
828
|
readonly vendor: string;
|
|
827
829
|
readonly activeTransport: TransportType | null;
|
|
@@ -847,7 +849,6 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
847
849
|
* especially for vendors with ephemeral connectId/deviceId.
|
|
848
850
|
*/
|
|
849
851
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
850
|
-
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
851
852
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
852
853
|
on(event: string, listener: DeviceEventListener): void;
|
|
853
854
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -1074,4 +1075,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
|
|
|
1074
1075
|
total: number;
|
|
1075
1076
|
}) => void): Promise<Response<TResult[]>>;
|
|
1076
1077
|
|
|
1077
|
-
export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignPsbtParams, type BtcSignTxParams, type BtcSignature, type BtcSignedPsbt, 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 DeviceJobQueueDeps, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type
|
|
1078
|
+
export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignPsbtParams, type BtcSignTxParams, type BtcSignature, type BtcSignedPsbt, 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 DeviceJobQueueDeps, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type 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 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_REQUEST_CANCELLED_TAG, UI_REQUEST_DEFAULT_TIMEOUT_MS, UI_REQUEST_PREEMPTED_TAG, UI_REQUEST_TIMEOUT_TAG, UI_RESPONSE, type UiRequestEvent, UiRequestRegistry, type UiResponseEvent, type VendorType, batchCall, bytesToHex, compareSemver, createBridgedConnector, deriveDeviceFingerprint, enrichErrorMessage, ensure0x, failure, hexToBytes, padHex64, stripHex, success };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,49 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HWK HardwareErrorCode — independent namespace from the legacy
|
|
3
|
+
* `@onekeyfe/shared` HardwareErrorCode (which occupies 0-902).
|
|
4
|
+
*
|
|
5
|
+
* All HWK codes are 5-digit (>= 10000) so the two tables never collide
|
|
6
|
+
* even if either side grows. Each sub-category gets a 100-slot block.
|
|
7
|
+
*
|
|
8
|
+
* 10000-10099 Generic / cross-cutting primitives
|
|
9
|
+
* 10100-10199 Device state
|
|
10
|
+
* 10200-10299 Firmware
|
|
11
|
+
* 10300-10399 Transport + OS-level permission
|
|
12
|
+
* 10400-10499 PIN / Passphrase
|
|
13
|
+
* 10500-10599 App lifecycle (wrong app, not open, too old)
|
|
14
|
+
* 10600-10999 RESERVED — future adapter-level categories
|
|
15
|
+
*
|
|
16
|
+
* 11000-11099 EVM APDU (reactive mapping)
|
|
17
|
+
* 11100-11199 Solana APDU
|
|
18
|
+
* 11200-11299 Tron APDU
|
|
19
|
+
* 11300-11399 BTC APDU
|
|
20
|
+
* 11400-11999 RESERVED — future chain APDU blocks (100 per chain)
|
|
21
|
+
*
|
|
22
|
+
* 12000-99999 RESERVED — future major categories
|
|
23
|
+
*/
|
|
1
24
|
declare enum HardwareErrorCode {
|
|
2
|
-
UnknownError =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
UnknownError = 10000,
|
|
26
|
+
UserRejected = 10001,
|
|
27
|
+
InvalidParams = 10002,
|
|
28
|
+
OperationTimeout = 10003,
|
|
29
|
+
MethodNotSupported = 10004,
|
|
30
|
+
DeviceNotFound = 10100,
|
|
31
|
+
DeviceDisconnected = 10101,
|
|
32
|
+
DeviceBusy = 10102,
|
|
33
|
+
DeviceLocked = 10103,
|
|
34
|
+
DeviceNotInitialized = 10104,
|
|
35
|
+
DeviceInBootloader = 10105,
|
|
36
|
+
DeviceMismatch = 10106,
|
|
37
|
+
FirmwareTooOld = 10200,
|
|
38
|
+
FirmwareUpdateRequired = 10201,
|
|
39
|
+
TransportError = 10300,
|
|
40
|
+
BridgeNotFound = 10301,
|
|
41
|
+
TransportNotAvailable = 10302,
|
|
42
|
+
/**
|
|
43
|
+
* OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
|
|
44
|
+
* unavailable, or dismissed. Consumers surface a single "please grant
|
|
45
|
+
* permission" toast and let the user retry manually.
|
|
46
|
+
*/
|
|
47
|
+
DevicePermissionDenied = 10303,
|
|
48
|
+
PinInvalid = 10400,
|
|
49
|
+
PinCancelled = 10401,
|
|
50
|
+
PassphraseRejected = 10402,
|
|
51
|
+
AppNotOpen = 10500,
|
|
52
|
+
WrongApp = 10501,
|
|
53
|
+
/** 0x911c Command code not supported — app predates current SDK. */
|
|
54
|
+
AppTooOld = 10502,
|
|
24
55
|
/** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
|
|
25
56
|
* user has not enabled Blind signing on the device. */
|
|
26
|
-
EvmBlindSigningRequired =
|
|
57
|
+
EvmBlindSigningRequired = 11000,
|
|
27
58
|
/** 0x6984 Plugin not installed */
|
|
28
|
-
EvmClearSignPluginMissing =
|
|
59
|
+
EvmClearSignPluginMissing = 11001,
|
|
29
60
|
/** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
|
|
30
|
-
EvmDataTooLarge =
|
|
61
|
+
EvmDataTooLarge = 11002,
|
|
31
62
|
/** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
|
|
32
|
-
EvmTxTypeNotSupported =
|
|
33
|
-
/** 0x911c Command code not supported — app predates current SDK */
|
|
34
|
-
AppTooOld = 7005,
|
|
63
|
+
EvmTxTypeNotSupported = 11003,
|
|
35
64
|
/** 0x6808 Blind signing disabled for this instruction. */
|
|
36
|
-
SolanaBlindSigningRequired =
|
|
65
|
+
SolanaBlindSigningRequired = 11100,
|
|
37
66
|
/** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
|
|
38
|
-
TronCustomContractRequired =
|
|
67
|
+
TronCustomContractRequired = 11200,
|
|
39
68
|
/** 0x6a8b Transactions Data setting disabled. */
|
|
40
|
-
TronDataSigningRequired =
|
|
69
|
+
TronDataSigningRequired = 11201,
|
|
41
70
|
/** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
|
|
42
|
-
TronSignByHashRequired =
|
|
71
|
+
TronSignByHashRequired = 11202,
|
|
43
72
|
/** 0xb008 Wallet policy HMAC mismatch or not registered. */
|
|
44
|
-
BtcWalletPolicyHmacMismatch =
|
|
73
|
+
BtcWalletPolicyHmacMismatch = 11300,
|
|
45
74
|
/** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
|
|
46
|
-
BtcUnexpectedState =
|
|
75
|
+
BtcUnexpectedState = 11301
|
|
47
76
|
}
|
|
48
77
|
|
|
49
78
|
interface Success<T> {
|
|
@@ -517,6 +546,7 @@ declare const UI_RESPONSE: {
|
|
|
517
546
|
readonly RECEIVE_QR_RESPONSE: "receive-qr-response";
|
|
518
547
|
readonly RECEIVE_SELECT_DEVICE: "receive-select-device";
|
|
519
548
|
readonly RECEIVE_DEVICE_CONNECT: "receive-device-connect";
|
|
549
|
+
readonly RECEIVE_DEVICE_PERMISSION: "receive-device-permission";
|
|
520
550
|
readonly RECEIVE_PREEMPTION: "receive-preemption";
|
|
521
551
|
readonly CANCEL: "cancel";
|
|
522
552
|
};
|
|
@@ -546,6 +576,11 @@ type UiResponseEvent = {
|
|
|
546
576
|
payload: {
|
|
547
577
|
confirmed: boolean;
|
|
548
578
|
};
|
|
579
|
+
} | {
|
|
580
|
+
type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;
|
|
581
|
+
payload: {
|
|
582
|
+
granted: boolean;
|
|
583
|
+
};
|
|
549
584
|
} | {
|
|
550
585
|
type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;
|
|
551
586
|
payload: {
|
|
@@ -616,7 +651,11 @@ type UiRequestEvent = {
|
|
|
616
651
|
};
|
|
617
652
|
} | {
|
|
618
653
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
619
|
-
payload:
|
|
654
|
+
payload: {
|
|
655
|
+
transportType: TransportType;
|
|
656
|
+
connectId?: string;
|
|
657
|
+
deviceId?: string;
|
|
658
|
+
};
|
|
620
659
|
} | {
|
|
621
660
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
622
661
|
payload: {
|
|
@@ -726,7 +765,11 @@ interface HardwareEventMap {
|
|
|
726
765
|
};
|
|
727
766
|
[UI_REQUEST.REQUEST_DEVICE_PERMISSION]: {
|
|
728
767
|
type: typeof UI_REQUEST.REQUEST_DEVICE_PERMISSION;
|
|
729
|
-
payload:
|
|
768
|
+
payload: {
|
|
769
|
+
transportType: TransportType;
|
|
770
|
+
connectId?: string;
|
|
771
|
+
deviceId?: string;
|
|
772
|
+
};
|
|
730
773
|
};
|
|
731
774
|
[UI_REQUEST.REQUEST_SELECT_DEVICE]: {
|
|
732
775
|
type: typeof UI_REQUEST.REQUEST_SELECT_DEVICE;
|
|
@@ -781,47 +824,6 @@ interface HardwareEventMap {
|
|
|
781
824
|
};
|
|
782
825
|
};
|
|
783
826
|
}
|
|
784
|
-
/**
|
|
785
|
-
* Same-process callbacks for prompts and OS-level permission.
|
|
786
|
-
* Cross-process flows use events + `uiResponse` + `UiRequestRegistry` instead.
|
|
787
|
-
*/
|
|
788
|
-
interface IUiHandler {
|
|
789
|
-
onPinRequest(device: DeviceInfo): Promise<string>;
|
|
790
|
-
onPassphraseRequest(device: DeviceInfo): Promise<string | PassphraseResponse>;
|
|
791
|
-
onQrDisplay(device: DeviceInfo, data: QrDisplayData): Promise<QrResponseData>;
|
|
792
|
-
/**
|
|
793
|
-
* Check if device access permission is already granted.
|
|
794
|
-
* Returns { granted, context? }.
|
|
795
|
-
* - granted: true → skip onDevicePermission
|
|
796
|
-
* - granted: false → adapter calls onDevicePermission with the context
|
|
797
|
-
* - context: consumer-defined data passed through to onDevicePermission
|
|
798
|
-
*
|
|
799
|
-
* When connectId/deviceId are undefined (searchDevices), check environment-level
|
|
800
|
-
* permissions (USB: any paired device exists; BLE: bluetooth on + location permission).
|
|
801
|
-
* When connectId/deviceId are provided (business methods), check device-level
|
|
802
|
-
* permissions (USB: target device authorized; BLE: bluetooth on + device connected).
|
|
803
|
-
*/
|
|
804
|
-
checkDevicePermission?(params: {
|
|
805
|
-
transportType: TransportType;
|
|
806
|
-
connectId?: string;
|
|
807
|
-
deviceId?: string;
|
|
808
|
-
}): Promise<{
|
|
809
|
-
granted: boolean;
|
|
810
|
-
context?: Record<string, unknown>;
|
|
811
|
-
}>;
|
|
812
|
-
/**
|
|
813
|
-
* Request device access permission from the user.
|
|
814
|
-
* Only called when checkDevicePermission returns granted: false (or is not set).
|
|
815
|
-
*
|
|
816
|
-
* The handler decides what to do based on transportType + context:
|
|
817
|
-
* - usb/hid: open pairing page or call requestWebUSBDevice
|
|
818
|
-
* - ble: enable bluetooth, request location permission, start scanning
|
|
819
|
-
*/
|
|
820
|
-
onDevicePermission(params: {
|
|
821
|
-
transportType: TransportType;
|
|
822
|
-
context?: Record<string, unknown>;
|
|
823
|
-
}): Promise<void>;
|
|
824
|
-
}
|
|
825
827
|
interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, ISolMethods, ITronMethods {
|
|
826
828
|
readonly vendor: string;
|
|
827
829
|
readonly activeTransport: TransportType | null;
|
|
@@ -847,7 +849,6 @@ interface IHardwareWallet<TConfig = unknown> extends IEvmMethods, IBtcMethods, I
|
|
|
847
849
|
* especially for vendors with ephemeral connectId/deviceId.
|
|
848
850
|
*/
|
|
849
851
|
getChainFingerprint(connectId: string, deviceId: string, chain: ChainForFingerprint): Promise<Response<string>>;
|
|
850
|
-
setUiHandler(handler: Partial<IUiHandler>): void;
|
|
851
852
|
on<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
852
853
|
on(event: string, listener: DeviceEventListener): void;
|
|
853
854
|
off<K extends keyof HardwareEventMap>(event: K, listener: (event: HardwareEventMap[K]) => void): void;
|
|
@@ -1074,4 +1075,4 @@ declare function batchCall<TParam, TResult>(params: TParam[], callFn: (p: TParam
|
|
|
1074
1075
|
total: number;
|
|
1075
1076
|
}) => void): Promise<Response<TResult[]>>;
|
|
1076
1077
|
|
|
1077
|
-
export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignPsbtParams, type BtcSignTxParams, type BtcSignature, type BtcSignedPsbt, 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 DeviceJobQueueDeps, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type
|
|
1078
|
+
export { type ActiveJobInfo, type BtcAddress, type BtcGetAddressParams, type BtcGetPublicKeyParams, type BtcPublicKey, type BtcRefTransaction, type BtcSignMsgParams, type BtcSignPsbtParams, type BtcSignTxParams, type BtcSignature, type BtcSignedPsbt, 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 DeviceJobQueueDeps, type DeviceTarget, EConnectorInteraction, type EIP712Domain, type EvmAddress, type EvmGetAddressParams, type EvmSignMsgParams, type EvmSignTxParams, type EvmSignTypedDataFull, type EvmSignTypedDataHash, type EvmSignTypedDataParams, type EvmSignature, type EvmSignedTx, type Failure, HardwareErrorCode, type HardwareEvent, type HardwareEventMap, type IBtcMethods, type IConnector, type IEvmMethods, type IHardwareBridge, type IHardwareWallet, type ISolMethods, type ITronMethods, type 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 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_REQUEST_CANCELLED_TAG, UI_REQUEST_DEFAULT_TIMEOUT_MS, UI_REQUEST_PREEMPTED_TAG, UI_REQUEST_TIMEOUT_TAG, UI_RESPONSE, type UiRequestEvent, UiRequestRegistry, type UiResponseEvent, type VendorType, batchCall, bytesToHex, compareSemver, createBridgedConnector, deriveDeviceFingerprint, enrichErrorMessage, ensure0x, failure, hexToBytes, padHex64, stripHex, success };
|
package/dist/index.js
CHANGED
|
@@ -53,39 +53,40 @@ module.exports = __toCommonJS(index_exports);
|
|
|
53
53
|
|
|
54
54
|
// src/types/errors.ts
|
|
55
55
|
var HardwareErrorCode = /* @__PURE__ */ ((HardwareErrorCode2) => {
|
|
56
|
-
HardwareErrorCode2[HardwareErrorCode2["UnknownError"] =
|
|
57
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
58
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
59
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
60
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
61
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
62
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
63
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
64
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
65
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
66
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
67
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
68
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
69
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
70
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
71
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
72
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
73
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
74
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
75
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
76
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
77
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
78
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
79
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
80
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
81
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
82
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
83
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
84
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
85
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
86
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
87
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
88
|
-
HardwareErrorCode2[HardwareErrorCode2["
|
|
56
|
+
HardwareErrorCode2[HardwareErrorCode2["UnknownError"] = 1e4] = "UnknownError";
|
|
57
|
+
HardwareErrorCode2[HardwareErrorCode2["UserRejected"] = 10001] = "UserRejected";
|
|
58
|
+
HardwareErrorCode2[HardwareErrorCode2["InvalidParams"] = 10002] = "InvalidParams";
|
|
59
|
+
HardwareErrorCode2[HardwareErrorCode2["OperationTimeout"] = 10003] = "OperationTimeout";
|
|
60
|
+
HardwareErrorCode2[HardwareErrorCode2["MethodNotSupported"] = 10004] = "MethodNotSupported";
|
|
61
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceNotFound"] = 10100] = "DeviceNotFound";
|
|
62
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceDisconnected"] = 10101] = "DeviceDisconnected";
|
|
63
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceBusy"] = 10102] = "DeviceBusy";
|
|
64
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceLocked"] = 10103] = "DeviceLocked";
|
|
65
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceNotInitialized"] = 10104] = "DeviceNotInitialized";
|
|
66
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceInBootloader"] = 10105] = "DeviceInBootloader";
|
|
67
|
+
HardwareErrorCode2[HardwareErrorCode2["DeviceMismatch"] = 10106] = "DeviceMismatch";
|
|
68
|
+
HardwareErrorCode2[HardwareErrorCode2["FirmwareTooOld"] = 10200] = "FirmwareTooOld";
|
|
69
|
+
HardwareErrorCode2[HardwareErrorCode2["FirmwareUpdateRequired"] = 10201] = "FirmwareUpdateRequired";
|
|
70
|
+
HardwareErrorCode2[HardwareErrorCode2["TransportError"] = 10300] = "TransportError";
|
|
71
|
+
HardwareErrorCode2[HardwareErrorCode2["BridgeNotFound"] = 10301] = "BridgeNotFound";
|
|
72
|
+
HardwareErrorCode2[HardwareErrorCode2["TransportNotAvailable"] = 10302] = "TransportNotAvailable";
|
|
73
|
+
HardwareErrorCode2[HardwareErrorCode2["DevicePermissionDenied"] = 10303] = "DevicePermissionDenied";
|
|
74
|
+
HardwareErrorCode2[HardwareErrorCode2["PinInvalid"] = 10400] = "PinInvalid";
|
|
75
|
+
HardwareErrorCode2[HardwareErrorCode2["PinCancelled"] = 10401] = "PinCancelled";
|
|
76
|
+
HardwareErrorCode2[HardwareErrorCode2["PassphraseRejected"] = 10402] = "PassphraseRejected";
|
|
77
|
+
HardwareErrorCode2[HardwareErrorCode2["AppNotOpen"] = 10500] = "AppNotOpen";
|
|
78
|
+
HardwareErrorCode2[HardwareErrorCode2["WrongApp"] = 10501] = "WrongApp";
|
|
79
|
+
HardwareErrorCode2[HardwareErrorCode2["AppTooOld"] = 10502] = "AppTooOld";
|
|
80
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmBlindSigningRequired"] = 11e3] = "EvmBlindSigningRequired";
|
|
81
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmClearSignPluginMissing"] = 11001] = "EvmClearSignPluginMissing";
|
|
82
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmDataTooLarge"] = 11002] = "EvmDataTooLarge";
|
|
83
|
+
HardwareErrorCode2[HardwareErrorCode2["EvmTxTypeNotSupported"] = 11003] = "EvmTxTypeNotSupported";
|
|
84
|
+
HardwareErrorCode2[HardwareErrorCode2["SolanaBlindSigningRequired"] = 11100] = "SolanaBlindSigningRequired";
|
|
85
|
+
HardwareErrorCode2[HardwareErrorCode2["TronCustomContractRequired"] = 11200] = "TronCustomContractRequired";
|
|
86
|
+
HardwareErrorCode2[HardwareErrorCode2["TronDataSigningRequired"] = 11201] = "TronDataSigningRequired";
|
|
87
|
+
HardwareErrorCode2[HardwareErrorCode2["TronSignByHashRequired"] = 11202] = "TronSignByHashRequired";
|
|
88
|
+
HardwareErrorCode2[HardwareErrorCode2["BtcWalletPolicyHmacMismatch"] = 11300] = "BtcWalletPolicyHmacMismatch";
|
|
89
|
+
HardwareErrorCode2[HardwareErrorCode2["BtcUnexpectedState"] = 11301] = "BtcUnexpectedState";
|
|
89
90
|
return HardwareErrorCode2;
|
|
90
91
|
})(HardwareErrorCode || {});
|
|
91
92
|
|
|
@@ -145,6 +146,7 @@ var UI_RESPONSE = {
|
|
|
145
146
|
RECEIVE_QR_RESPONSE: "receive-qr-response",
|
|
146
147
|
RECEIVE_SELECT_DEVICE: "receive-select-device",
|
|
147
148
|
RECEIVE_DEVICE_CONNECT: "receive-device-connect",
|
|
149
|
+
RECEIVE_DEVICE_PERMISSION: "receive-device-permission",
|
|
148
150
|
RECEIVE_PREEMPTION: "receive-preemption",
|
|
149
151
|
CANCEL: "cancel"
|
|
150
152
|
};
|
|
@@ -384,6 +386,7 @@ var RESPONSE_TO_REQUEST = {
|
|
|
384
386
|
[UI_RESPONSE.RECEIVE_PASSPHRASE_ON_DEVICE]: UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE,
|
|
385
387
|
[UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,
|
|
386
388
|
[UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,
|
|
389
|
+
[UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
387
390
|
[UI_RESPONSE.RECEIVE_PREEMPTION]: UI_REQUEST.REQUEST_PREEMPTION
|
|
388
391
|
// RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.
|
|
389
392
|
};
|
|
@@ -505,51 +508,51 @@ function bytesToHex2(bytes) {
|
|
|
505
508
|
// src/utils/errorMessages.ts
|
|
506
509
|
function enrichErrorMessage(code, originalMessage) {
|
|
507
510
|
switch (code) {
|
|
508
|
-
case
|
|
511
|
+
case 10400 /* PinInvalid */:
|
|
509
512
|
return `${originalMessage}. Please re-enter your PIN.`;
|
|
510
|
-
case
|
|
513
|
+
case 10401 /* PinCancelled */:
|
|
511
514
|
return `${originalMessage}. PIN entry was cancelled.`;
|
|
512
|
-
case
|
|
515
|
+
case 10102 /* DeviceBusy */:
|
|
513
516
|
return `${originalMessage}. The device is in use by another application. Close other wallet apps and try again.`;
|
|
514
|
-
case
|
|
517
|
+
case 10101 /* DeviceDisconnected */:
|
|
515
518
|
return `${originalMessage}. Please reconnect the device and try again.`;
|
|
516
|
-
case
|
|
519
|
+
case 10103 /* DeviceLocked */:
|
|
517
520
|
return `${originalMessage}. Please unlock your device and try again.`;
|
|
518
|
-
case
|
|
521
|
+
case 10001 /* UserRejected */:
|
|
519
522
|
return `${originalMessage}. The request was rejected on the device.`;
|
|
520
|
-
case
|
|
523
|
+
case 10501 /* WrongApp */:
|
|
521
524
|
return `${originalMessage}. Please open the correct app on your device.`;
|
|
522
|
-
case
|
|
525
|
+
case 10500 /* AppNotOpen */:
|
|
523
526
|
return `${originalMessage}. The required app is not installed on the device.`;
|
|
524
|
-
case
|
|
527
|
+
case 10302 /* TransportNotAvailable */:
|
|
525
528
|
return `${originalMessage}. Ensure the device bridge/transport is available and running.`;
|
|
526
|
-
case
|
|
529
|
+
case 10200 /* FirmwareTooOld */:
|
|
527
530
|
return `${originalMessage}. Please update your device firmware.`;
|
|
528
|
-
case
|
|
531
|
+
case 10104 /* DeviceNotInitialized */:
|
|
529
532
|
return `${originalMessage}. The device may need to be set up first.`;
|
|
530
|
-
case
|
|
533
|
+
case 10003 /* OperationTimeout */:
|
|
531
534
|
return `${originalMessage}. The operation timed out. Please try again.`;
|
|
532
|
-
case
|
|
535
|
+
case 11e3 /* EvmBlindSigningRequired */:
|
|
533
536
|
return "Ledger: Blind signing not enabled in Ethereum app.";
|
|
534
|
-
case
|
|
537
|
+
case 11001 /* EvmClearSignPluginMissing */:
|
|
535
538
|
return "Ledger: Required plugin not installed (install via Ledger Live).";
|
|
536
|
-
case
|
|
539
|
+
case 11002 /* EvmDataTooLarge */:
|
|
537
540
|
return "Ledger: Transaction data too large for device memory.";
|
|
538
|
-
case
|
|
541
|
+
case 11003 /* EvmTxTypeNotSupported */:
|
|
539
542
|
return "Ledger: Transaction type not supported by current Ethereum app.";
|
|
540
|
-
case
|
|
543
|
+
case 10502 /* AppTooOld */:
|
|
541
544
|
return "Ledger: App out of date (update via Ledger Live).";
|
|
542
|
-
case
|
|
545
|
+
case 11100 /* SolanaBlindSigningRequired */:
|
|
543
546
|
return "Blind signing disabled in the Solana app.";
|
|
544
|
-
case
|
|
547
|
+
case 11200 /* TronCustomContractRequired */:
|
|
545
548
|
return "Custom Contracts setting disabled in the Tron app.";
|
|
546
|
-
case
|
|
549
|
+
case 11201 /* TronDataSigningRequired */:
|
|
547
550
|
return "Transactions Data setting disabled in the Tron app.";
|
|
548
|
-
case
|
|
551
|
+
case 11202 /* TronSignByHashRequired */:
|
|
549
552
|
return "Sign by Hash setting disabled in the Tron app.";
|
|
550
|
-
case
|
|
553
|
+
case 11300 /* BtcWalletPolicyHmacMismatch */:
|
|
551
554
|
return "Wallet policy not registered or HMAC mismatch.";
|
|
552
|
-
case
|
|
555
|
+
case 11301 /* BtcUnexpectedState */:
|
|
553
556
|
return "Signing aborted due to unexpected device state.";
|
|
554
557
|
default:
|
|
555
558
|
return originalMessage;
|