@onekeyfe/hwk-adapter-core 1.2.0-alpha.8 → 1.2.0-alpha.80
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/chunk-67BP77GT.mjs +151 -0
- package/dist/chunk-67BP77GT.mjs.map +1 -0
- package/dist/chunk-BAGEFFFY.js +151 -0
- package/dist/chunk-BAGEFFFY.js.map +1 -0
- package/dist/chunk-SK7ZF33J.js +151 -0
- package/dist/chunk-SK7ZF33J.js.map +1 -0
- package/dist/chunk-U63HTLGJ.mjs +151 -0
- package/dist/chunk-U63HTLGJ.mjs.map +1 -0
- package/dist/errors.d.mts +205 -0
- package/dist/errors.d.ts +205 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +13 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.d.mts +657 -274
- package/dist/index.d.ts +657 -274
- package/dist/index.js +452 -355
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +401 -247
- package/dist/index.mjs.map +1 -1
- package/dist/ui-events-Cb7haAeE.d.mts +128 -0
- package/dist/ui-events-Cb7haAeE.d.ts +128 -0
- package/dist/ui-events.d.mts +1 -0
- package/dist/ui-events.d.ts +1 -0
- package/dist/ui-events.js +21 -0
- package/dist/ui-events.js.map +1 -0
- package/dist/ui-events.mjs +21 -0
- package/dist/ui-events.mjs.map +1 -0
- package/package.json +22 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// src/events/ui-request.ts
|
|
2
|
+
var UI_EVENT = "UI_EVENT";
|
|
3
|
+
var UI_REQUEST = {
|
|
4
|
+
REQUEST_PIN: "ui-request-pin",
|
|
5
|
+
REQUEST_PASSPHRASE: "ui-request-passphrase",
|
|
6
|
+
// One-way UI notification: device is waiting for passphrase entry on-device.
|
|
7
|
+
// The prompt response path remains RECEIVE_PASSPHRASE with passphraseOnDevice=true.
|
|
8
|
+
REQUEST_PASSPHRASE_ON_DEVICE: "ui-request-passphrase-on-device",
|
|
9
|
+
REQUEST_BUTTON: "ui-request-button",
|
|
10
|
+
REQUEST_QR_DISPLAY: "ui-request-qr-display",
|
|
11
|
+
REQUEST_QR_SCAN: "ui-request-qr-scan",
|
|
12
|
+
REQUEST_DEVICE_PERMISSION: "ui-request-device-permission",
|
|
13
|
+
REQUEST_SELECT_DEVICE: "ui-request-select-device",
|
|
14
|
+
REQUEST_DEVICE_CONNECT: "ui-request-device-connect",
|
|
15
|
+
// Ledger BTC App: account index >= 100 requires display=true. Adapter asks
|
|
16
|
+
// the user once per session before promoting the call.
|
|
17
|
+
REQUEST_BTC_HIGH_INDEX_CONFIRM: "ui-request-btc-high-index-confirm",
|
|
18
|
+
// Required app is not installed; with autoInstallApp on, ask the user
|
|
19
|
+
// whether to install it before retrying the operation.
|
|
20
|
+
REQUEST_INSTALL_APP: "ui-request-install-app",
|
|
21
|
+
REQUEST_PREEMPTION: "ui-request-preemption",
|
|
22
|
+
REQUEST_TREZOR_THP_PAIRING: "ui-request-trezor-thp-pairing",
|
|
23
|
+
CLOSE_UI_WINDOW: "ui-close",
|
|
24
|
+
DEVICE_PROGRESS: "ui-device_progress",
|
|
25
|
+
FIRMWARE_PROGRESS: "ui-firmware-progress",
|
|
26
|
+
FIRMWARE_TIP: "ui-firmware-tip"
|
|
27
|
+
};
|
|
28
|
+
var UI_RESPONSE = {
|
|
29
|
+
RECEIVE_PIN: "receive-pin",
|
|
30
|
+
RECEIVE_PASSPHRASE: "receive-passphrase",
|
|
31
|
+
RECEIVE_QR_RESPONSE: "receive-qr-response",
|
|
32
|
+
RECEIVE_SELECT_DEVICE: "receive-select-device",
|
|
33
|
+
RECEIVE_DEVICE_CONNECT: "receive-device-connect",
|
|
34
|
+
RECEIVE_DEVICE_PERMISSION: "receive-device-permission",
|
|
35
|
+
RECEIVE_BTC_HIGH_INDEX_CONFIRM: "receive-btc-high-index-confirm",
|
|
36
|
+
RECEIVE_INSTALL_APP: "receive-install-app",
|
|
37
|
+
RECEIVE_PREEMPTION: "receive-preemption",
|
|
38
|
+
RECEIVE_TREZOR_THP_PAIRING: "receive-trezor-thp-pairing",
|
|
39
|
+
CANCEL: "cancel"
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/utils/UiRequestRegistry.ts
|
|
43
|
+
var UI_REQUEST_DEFAULT_TIMEOUT_MS = 6e5;
|
|
44
|
+
var RESPONSE_TO_REQUEST = {
|
|
45
|
+
[UI_RESPONSE.RECEIVE_PIN]: UI_REQUEST.REQUEST_PIN,
|
|
46
|
+
[UI_RESPONSE.RECEIVE_PASSPHRASE]: UI_REQUEST.REQUEST_PASSPHRASE,
|
|
47
|
+
[UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,
|
|
48
|
+
[UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,
|
|
49
|
+
[UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,
|
|
50
|
+
[UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM]: UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM,
|
|
51
|
+
[UI_RESPONSE.RECEIVE_INSTALL_APP]: UI_REQUEST.REQUEST_INSTALL_APP,
|
|
52
|
+
[UI_RESPONSE.RECEIVE_PREEMPTION]: UI_REQUEST.REQUEST_PREEMPTION,
|
|
53
|
+
[UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING]: UI_REQUEST.REQUEST_TREZOR_THP_PAIRING
|
|
54
|
+
// RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.
|
|
55
|
+
};
|
|
56
|
+
var UI_REQUEST_PREEMPTED_TAG = "UiRequestPreempted";
|
|
57
|
+
var UI_REQUEST_CANCELLED_TAG = "UiRequestCancelled";
|
|
58
|
+
var UI_REQUEST_TIMEOUT_TAG = "UiRequestTimeout";
|
|
59
|
+
var UiRequestRegistry = class {
|
|
60
|
+
constructor() {
|
|
61
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
62
|
+
}
|
|
63
|
+
wait(requestType, options) {
|
|
64
|
+
const existing = this.pending.get(requestType);
|
|
65
|
+
if (existing) {
|
|
66
|
+
clearTimeout(existing.timer);
|
|
67
|
+
this.pending.delete(requestType);
|
|
68
|
+
existing.reject(
|
|
69
|
+
Object.assign(new Error(`UI request '${requestType}' was superseded by a new request`), {
|
|
70
|
+
_tag: UI_REQUEST_PREEMPTED_TAG
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const timeoutMs = options?.timeoutMs ?? UI_REQUEST_DEFAULT_TIMEOUT_MS;
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const timer = setTimeout(() => {
|
|
77
|
+
if (this.pending.get(requestType)?.timer === timer) {
|
|
78
|
+
this.pending.delete(requestType);
|
|
79
|
+
reject(
|
|
80
|
+
Object.assign(new Error(`UI request '${requestType}' timed out after ${timeoutMs}ms`), {
|
|
81
|
+
_tag: UI_REQUEST_TIMEOUT_TAG
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}, timeoutMs);
|
|
86
|
+
this.pending.set(requestType, {
|
|
87
|
+
resolve,
|
|
88
|
+
reject,
|
|
89
|
+
timer
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
resolve(responseType, payload) {
|
|
94
|
+
let requestType = RESPONSE_TO_REQUEST[responseType];
|
|
95
|
+
if (responseType === UI_RESPONSE.RECEIVE_QR_RESPONSE) {
|
|
96
|
+
if (this.pending.has(UI_REQUEST.REQUEST_QR_DISPLAY)) {
|
|
97
|
+
requestType = UI_REQUEST.REQUEST_QR_DISPLAY;
|
|
98
|
+
} else if (this.pending.has(UI_REQUEST.REQUEST_QR_SCAN)) {
|
|
99
|
+
requestType = UI_REQUEST.REQUEST_QR_SCAN;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!requestType) return;
|
|
103
|
+
const entry = this.pending.get(requestType);
|
|
104
|
+
if (!entry) return;
|
|
105
|
+
clearTimeout(entry.timer);
|
|
106
|
+
this.pending.delete(requestType);
|
|
107
|
+
entry.resolve(payload);
|
|
108
|
+
}
|
|
109
|
+
cancel(requestType) {
|
|
110
|
+
if (requestType) {
|
|
111
|
+
const entry = this.pending.get(requestType);
|
|
112
|
+
if (!entry) return;
|
|
113
|
+
clearTimeout(entry.timer);
|
|
114
|
+
this.pending.delete(requestType);
|
|
115
|
+
entry.reject(
|
|
116
|
+
Object.assign(new Error(`UI request '${requestType}' was cancelled`), {
|
|
117
|
+
_tag: UI_REQUEST_CANCELLED_TAG
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (const [type, entry] of this.pending) {
|
|
123
|
+
clearTimeout(entry.timer);
|
|
124
|
+
entry.reject(
|
|
125
|
+
Object.assign(new Error(`UI request '${type}' was cancelled`), {
|
|
126
|
+
_tag: UI_REQUEST_CANCELLED_TAG
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
this.pending.clear();
|
|
131
|
+
}
|
|
132
|
+
reset() {
|
|
133
|
+
this.cancel();
|
|
134
|
+
}
|
|
135
|
+
hasPending(requestType) {
|
|
136
|
+
if (requestType) return this.pending.has(requestType);
|
|
137
|
+
return this.pending.size > 0;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
UI_EVENT,
|
|
143
|
+
UI_REQUEST,
|
|
144
|
+
UI_RESPONSE,
|
|
145
|
+
UI_REQUEST_DEFAULT_TIMEOUT_MS,
|
|
146
|
+
UI_REQUEST_PREEMPTED_TAG,
|
|
147
|
+
UI_REQUEST_CANCELLED_TAG,
|
|
148
|
+
UI_REQUEST_TIMEOUT_TAG,
|
|
149
|
+
UiRequestRegistry
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=chunk-U63HTLGJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/events/ui-request.ts","../src/utils/UiRequestRegistry.ts"],"sourcesContent":["import type { QrResponseData } from '../types/qr';\n\nexport const UI_EVENT = 'UI_EVENT';\n\nexport const UI_REQUEST = {\n REQUEST_PIN: 'ui-request-pin',\n REQUEST_PASSPHRASE: 'ui-request-passphrase',\n // One-way UI notification: device is waiting for passphrase entry on-device.\n // The prompt response path remains RECEIVE_PASSPHRASE with passphraseOnDevice=true.\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 REQUEST_DEVICE_CONNECT: 'ui-request-device-connect',\n // Ledger BTC App: account index >= 100 requires display=true. Adapter asks\n // the user once per session before promoting the call.\n REQUEST_BTC_HIGH_INDEX_CONFIRM: 'ui-request-btc-high-index-confirm',\n // Required app is not installed; with autoInstallApp on, ask the user\n // whether to install it before retrying the operation.\n REQUEST_INSTALL_APP: 'ui-request-install-app',\n REQUEST_PREEMPTION: 'ui-request-preemption',\n REQUEST_TREZOR_THP_PAIRING: 'ui-request-trezor-thp-pairing',\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_QR_RESPONSE: 'receive-qr-response',\n RECEIVE_SELECT_DEVICE: 'receive-select-device',\n RECEIVE_DEVICE_CONNECT: 'receive-device-connect',\n RECEIVE_DEVICE_PERMISSION: 'receive-device-permission',\n RECEIVE_BTC_HIGH_INDEX_CONFIRM: 'receive-btc-high-index-confirm',\n RECEIVE_INSTALL_APP: 'receive-install-app',\n RECEIVE_PREEMPTION: 'receive-preemption',\n RECEIVE_TREZOR_THP_PAIRING: 'receive-trezor-thp-pairing',\n CANCEL: 'cancel',\n} as const;\n\nexport type DevicePermissionDeniedReason =\n | 'bluetoothTurnedOff'\n | 'permissionDenied'\n | (string & Record<never, never>);\n\nexport type DevicePermissionResponse = {\n granted: boolean;\n reason?: DevicePermissionDeniedReason;\n message?: string;\n};\n\nexport type UiResponseEvent =\n | {\n type: typeof UI_RESPONSE.RECEIVE_PIN;\n payload: string;\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;\n payload: {\n value: string;\n passphraseOnDevice?: boolean;\n save?: boolean;\n };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_QR_RESPONSE;\n payload: QrResponseData;\n }\n | {\n // sdkConnectId echoes one of the DeviceInfo.connectId values emitted in\n // the REQUEST_SELECT_DEVICE event's `devices` list. Scope is the current\n // search session; may be ephemeral (e.g. Ledger USB DMK UUID).\n type: typeof UI_RESPONSE.RECEIVE_SELECT_DEVICE;\n payload: { sdkConnectId: string };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_DEVICE_CONNECT;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_DEVICE_PERMISSION;\n payload: DevicePermissionResponse;\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_INSTALL_APP;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_PREEMPTION;\n payload: { confirmed: boolean };\n }\n | {\n type: typeof UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING;\n payload: {\n selectedMethod?: number | string;\n tag?: string;\n };\n }\n | {\n type: typeof UI_RESPONSE.CANCEL;\n payload?: undefined;\n };\n","import { UI_REQUEST, UI_RESPONSE } from '../events/ui-request';\n\n/** 10 min — every UI request is human-in-the-loop; bias toward \"wait long\". */\nexport const UI_REQUEST_DEFAULT_TIMEOUT_MS = 600_000;\n\nconst RESPONSE_TO_REQUEST: Record<string, string> = {\n [UI_RESPONSE.RECEIVE_PIN]: UI_REQUEST.REQUEST_PIN,\n [UI_RESPONSE.RECEIVE_PASSPHRASE]: UI_REQUEST.REQUEST_PASSPHRASE,\n [UI_RESPONSE.RECEIVE_SELECT_DEVICE]: UI_REQUEST.REQUEST_SELECT_DEVICE,\n [UI_RESPONSE.RECEIVE_DEVICE_CONNECT]: UI_REQUEST.REQUEST_DEVICE_CONNECT,\n [UI_RESPONSE.RECEIVE_DEVICE_PERMISSION]: UI_REQUEST.REQUEST_DEVICE_PERMISSION,\n [UI_RESPONSE.RECEIVE_BTC_HIGH_INDEX_CONFIRM]: UI_REQUEST.REQUEST_BTC_HIGH_INDEX_CONFIRM,\n [UI_RESPONSE.RECEIVE_INSTALL_APP]: UI_REQUEST.REQUEST_INSTALL_APP,\n [UI_RESPONSE.RECEIVE_PREEMPTION]: UI_REQUEST.REQUEST_PREEMPTION,\n [UI_RESPONSE.RECEIVE_TREZOR_THP_PAIRING]: UI_REQUEST.REQUEST_TREZOR_THP_PAIRING,\n // RECEIVE_QR_RESPONSE maps to QR_DISPLAY or QR_SCAN — resolved dynamically below.\n};\n\nexport const UI_REQUEST_PREEMPTED_TAG = 'UiRequestPreempted';\nexport const UI_REQUEST_CANCELLED_TAG = 'UiRequestCancelled';\nexport const UI_REQUEST_TIMEOUT_TAG = 'UiRequestTimeout';\n\ntype PendingEntry = {\n resolve: (payload: unknown) => void;\n reject: (error: Error) => void;\n timer: ReturnType<typeof setTimeout>;\n};\n\n/**\n * Per-type single-slot registry for adapter-level UI requests. A new `wait`\n * of the same type supersedes (rejects) the prior pending entry. With the\n * job queue running globally serially, cross-type collisions don't occur in\n * normal flow — same-type preemption is a defensive measure for callers\n * that fire the same request twice without waiting on the first.\n *\n * Unknown response types are dropped silently so the public `uiResponse`\n * entry never throws.\n */\nexport class UiRequestRegistry {\n private pending = new Map<string, PendingEntry>();\n\n wait<T = unknown>(requestType: string, options?: { timeoutMs?: number }): Promise<T> {\n const existing = this.pending.get(requestType);\n if (existing) {\n clearTimeout(existing.timer);\n this.pending.delete(requestType);\n existing.reject(\n Object.assign(new Error(`UI request '${requestType}' was superseded by a new request`), {\n _tag: UI_REQUEST_PREEMPTED_TAG,\n })\n );\n }\n\n const timeoutMs = options?.timeoutMs ?? UI_REQUEST_DEFAULT_TIMEOUT_MS;\n\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => {\n if (this.pending.get(requestType)?.timer === timer) {\n this.pending.delete(requestType);\n reject(\n Object.assign(new Error(`UI request '${requestType}' timed out after ${timeoutMs}ms`), {\n _tag: UI_REQUEST_TIMEOUT_TAG,\n })\n );\n }\n }, timeoutMs);\n\n this.pending.set(requestType, {\n resolve: resolve as (payload: unknown) => void,\n reject,\n timer,\n });\n });\n }\n\n resolve(responseType: string, payload: unknown): void {\n let requestType = RESPONSE_TO_REQUEST[responseType];\n if (responseType === UI_RESPONSE.RECEIVE_QR_RESPONSE) {\n if (this.pending.has(UI_REQUEST.REQUEST_QR_DISPLAY)) {\n requestType = UI_REQUEST.REQUEST_QR_DISPLAY;\n } else if (this.pending.has(UI_REQUEST.REQUEST_QR_SCAN)) {\n requestType = UI_REQUEST.REQUEST_QR_SCAN;\n }\n }\n if (!requestType) return;\n\n const entry = this.pending.get(requestType);\n if (!entry) return;\n\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.resolve(payload);\n }\n\n cancel(requestType?: string): void {\n if (requestType) {\n const entry = this.pending.get(requestType);\n if (!entry) return;\n clearTimeout(entry.timer);\n this.pending.delete(requestType);\n entry.reject(\n Object.assign(new Error(`UI request '${requestType}' was cancelled`), {\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n return;\n }\n\n for (const [type, entry] of this.pending) {\n clearTimeout(entry.timer);\n entry.reject(\n Object.assign(new Error(`UI request '${type}' was cancelled`), {\n _tag: UI_REQUEST_CANCELLED_TAG,\n })\n );\n }\n this.pending.clear();\n }\n\n reset(): void {\n this.cancel();\n }\n\n hasPending(requestType?: string): boolean {\n if (requestType) return this.pending.has(requestType);\n return this.pending.size > 0;\n }\n}\n"],"mappings":";AAEO,IAAM,WAAW;AAEjB,IAAM,aAAa;AAAA,EACxB,aAAa;AAAA,EACb,oBAAoB;AAAA;AAAA;AAAA,EAGpB,8BAA8B;AAAA,EAC9B,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,2BAA2B;AAAA,EAC3B,uBAAuB;AAAA,EACvB,wBAAwB;AAAA;AAAA;AAAA,EAGxB,gCAAgC;AAAA;AAAA;AAAA,EAGhC,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,4BAA4B;AAAA,EAC5B,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,cAAc;AAChB;AAEO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,uBAAuB;AAAA,EACvB,wBAAwB;AAAA,EACxB,2BAA2B;AAAA,EAC3B,gCAAgC;AAAA,EAChC,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,4BAA4B;AAAA,EAC5B,QAAQ;AACV;;;ACvCO,IAAM,gCAAgC;AAE7C,IAAM,sBAA8C;AAAA,EAClD,CAAC,YAAY,WAAW,GAAG,WAAW;AAAA,EACtC,CAAC,YAAY,kBAAkB,GAAG,WAAW;AAAA,EAC7C,CAAC,YAAY,qBAAqB,GAAG,WAAW;AAAA,EAChD,CAAC,YAAY,sBAAsB,GAAG,WAAW;AAAA,EACjD,CAAC,YAAY,yBAAyB,GAAG,WAAW;AAAA,EACpD,CAAC,YAAY,8BAA8B,GAAG,WAAW;AAAA,EACzD,CAAC,YAAY,mBAAmB,GAAG,WAAW;AAAA,EAC9C,CAAC,YAAY,kBAAkB,GAAG,WAAW;AAAA,EAC7C,CAAC,YAAY,0BAA0B,GAAG,WAAW;AAAA;AAEvD;AAEO,IAAM,2BAA2B;AACjC,IAAM,2BAA2B;AACjC,IAAM,yBAAyB;AAkB/B,IAAM,oBAAN,MAAwB;AAAA,EAAxB;AACL,SAAQ,UAAU,oBAAI,IAA0B;AAAA;AAAA,EAEhD,KAAkB,aAAqB,SAA8C;AACnF,UAAM,WAAW,KAAK,QAAQ,IAAI,WAAW;AAC7C,QAAI,UAAU;AACZ,mBAAa,SAAS,KAAK;AAC3B,WAAK,QAAQ,OAAO,WAAW;AAC/B,eAAS;AAAA,QACP,OAAO,OAAO,IAAI,MAAM,eAAe,WAAW,mCAAmC,GAAG;AAAA,UACtF,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAEA,UAAM,YAAY,SAAS,aAAa;AAExC,WAAO,IAAI,QAAW,CAAC,SAAS,WAAW;AACzC,YAAM,QAAQ,WAAW,MAAM;AAC7B,YAAI,KAAK,QAAQ,IAAI,WAAW,GAAG,UAAU,OAAO;AAClD,eAAK,QAAQ,OAAO,WAAW;AAC/B;AAAA,YACE,OAAO,OAAO,IAAI,MAAM,eAAe,WAAW,qBAAqB,SAAS,IAAI,GAAG;AAAA,cACrF,MAAM;AAAA,YACR,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,SAAS;AAEZ,WAAK,QAAQ,IAAI,aAAa;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,cAAsB,SAAwB;AACpD,QAAI,cAAc,oBAAoB,YAAY;AAClD,QAAI,iBAAiB,YAAY,qBAAqB;AACpD,UAAI,KAAK,QAAQ,IAAI,WAAW,kBAAkB,GAAG;AACnD,sBAAc,WAAW;AAAA,MAC3B,WAAW,KAAK,QAAQ,IAAI,WAAW,eAAe,GAAG;AACvD,sBAAc,WAAW;AAAA,MAC3B;AAAA,IACF;AACA,QAAI,CAAC,YAAa;AAElB,UAAM,QAAQ,KAAK,QAAQ,IAAI,WAAW;AAC1C,QAAI,CAAC,MAAO;AAEZ,iBAAa,MAAM,KAAK;AACxB,SAAK,QAAQ,OAAO,WAAW;AAC/B,UAAM,QAAQ,OAAO;AAAA,EACvB;AAAA,EAEA,OAAO,aAA4B;AACjC,QAAI,aAAa;AACf,YAAM,QAAQ,KAAK,QAAQ,IAAI,WAAW;AAC1C,UAAI,CAAC,MAAO;AACZ,mBAAa,MAAM,KAAK;AACxB,WAAK,QAAQ,OAAO,WAAW;AAC/B,YAAM;AAAA,QACJ,OAAO,OAAO,IAAI,MAAM,eAAe,WAAW,iBAAiB,GAAG;AAAA,UACpE,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AACA;AAAA,IACF;AAEA,eAAW,CAAC,MAAM,KAAK,KAAK,KAAK,SAAS;AACxC,mBAAa,MAAM,KAAK;AACxB,YAAM;AAAA,QACJ,OAAO,OAAO,IAAI,MAAM,eAAe,IAAI,iBAAiB,GAAG;AAAA,UAC7D,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AACA,SAAK,QAAQ,MAAM;AAAA,EACrB;AAAA,EAEA,QAAc;AACZ,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,WAAW,aAA+B;AACxC,QAAI,YAAa,QAAO,KAAK,QAAQ,IAAI,WAAW;AACpD,WAAO,KAAK,QAAQ,OAAO;AAAA,EAC7B;AACF;","names":[]}
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
*/
|
|
24
|
+
declare enum HardwareErrorCode {
|
|
25
|
+
UnknownError = 10000,
|
|
26
|
+
UserRejected = 10001,
|
|
27
|
+
InvalidParams = 10002,
|
|
28
|
+
OperationTimeout = 10003,
|
|
29
|
+
MethodNotSupported = 10004,
|
|
30
|
+
/** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */
|
|
31
|
+
UserAborted = 10005,
|
|
32
|
+
DeviceNotFound = 10100,
|
|
33
|
+
DeviceDisconnected = 10101,
|
|
34
|
+
DeviceBusy = 10102,
|
|
35
|
+
DeviceLocked = 10103,
|
|
36
|
+
DeviceNotInitialized = 10104,
|
|
37
|
+
DeviceInBootloader = 10105,
|
|
38
|
+
DeviceMismatch = 10106,
|
|
39
|
+
/** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */
|
|
40
|
+
DeviceAppStuck = 10107,
|
|
41
|
+
/** Vendor (Ledger / Trezor) doesn't support the chain at all. */
|
|
42
|
+
ChainNotSupported = 10108,
|
|
43
|
+
/** Current operation supports only one connected device. */
|
|
44
|
+
DeviceOneDeviceOnly = 10109,
|
|
45
|
+
/**
|
|
46
|
+
* The device rejected the requested derivation path (Trezor Failure_DataError
|
|
47
|
+
* "Forbidden key path") — the path is non-standard or its index is outside the
|
|
48
|
+
* range the device's safety checks allow. Distinct from ChainNotSupported
|
|
49
|
+
* (whole chain) and MethodNotSupported (the operation/method itself).
|
|
50
|
+
*/
|
|
51
|
+
DevicePathForbidden = 10110,
|
|
52
|
+
/** Busy with our own in-flight request (queue guard / firmware Failure_Busy), not another app — wait and retry, don't close other apps. */
|
|
53
|
+
DeviceBusyInternal = 10111,
|
|
54
|
+
FirmwareTooOld = 10200,
|
|
55
|
+
FirmwareUpdateRequired = 10201,
|
|
56
|
+
TransportError = 10300,
|
|
57
|
+
BridgeNotFound = 10301,
|
|
58
|
+
TransportNotAvailable = 10302,
|
|
59
|
+
/**
|
|
60
|
+
* OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
|
|
61
|
+
* unavailable, or dismissed. Consumers surface a single "please grant
|
|
62
|
+
* permission" toast and let the user retry manually.
|
|
63
|
+
*/
|
|
64
|
+
DevicePermissionDenied = 10303,
|
|
65
|
+
/**
|
|
66
|
+
* BLE SMP pairing did not complete within the GATT bonding window.
|
|
67
|
+
* GATT connected but the device didn't acknowledge SMP — typically
|
|
68
|
+
* because the user didn't confirm the passkey on the device, or the
|
|
69
|
+
* device went out of range mid-pairing. Distinct from OperationTimeout
|
|
70
|
+
* (generic) and from DeviceLocked (Secure Element actually locked).
|
|
71
|
+
*/
|
|
72
|
+
BlePairingTimeout = 10304,
|
|
73
|
+
/** Remote network failure reaching a vendor's servers (HTTP/WS). Distinct from TransportError (local USB/BLE link). */
|
|
74
|
+
NetworkError = 10305,
|
|
75
|
+
/**
|
|
76
|
+
* Host-managed pairing handshake failed (Trezor THP). The device rejected the
|
|
77
|
+
* pairing exchange — e.g. CodeEntry: the user mistyped the code shown on the
|
|
78
|
+
* device, so the CPace tag didn't match ("Unexpected Code Entry Tag").
|
|
79
|
+
* Recoverable: the user re-pairs and re-enters the code. Distinct from
|
|
80
|
+
* BlePairingTimeout (BLE SMP bonding window) and UserRejected (on-device
|
|
81
|
+
* reject button).
|
|
82
|
+
*/
|
|
83
|
+
ThpPairingFailed = 10306,
|
|
84
|
+
/**
|
|
85
|
+
* The OS-level BLE bond is stale/invalid, so the device rejected link
|
|
86
|
+
* encryption: Android GATT_INSUF_AUTHENTICATION (status 5) or iOS "Peer
|
|
87
|
+
* removed pairing information". Happens after the device is wiped/re-flashed
|
|
88
|
+
* or unpaired elsewhere while the host still holds an old bond. The SDK cannot
|
|
89
|
+
* remove an OS bond — the user must forget the device in system Bluetooth
|
|
90
|
+
* settings and re-pair. Distinct from BlePairingTimeout (SMP window) and
|
|
91
|
+
* ThpPairingFailed (THP code mismatch).
|
|
92
|
+
*/
|
|
93
|
+
BleBondInvalid = 10307,
|
|
94
|
+
/**
|
|
95
|
+
* A stored THP pairing credential was rejected by the device during the
|
|
96
|
+
* handshake (device returned completion `state=0`), so the autoconnect session
|
|
97
|
+
* could not be established. The SDK discards the stale credential; recovery is
|
|
98
|
+
* a fresh pairing. Distinct from ThpPairingFailed (user mistyped the code
|
|
99
|
+
* during an *active* pairing) and BleBondInvalid (OS-level BLE bond).
|
|
100
|
+
*/
|
|
101
|
+
ThpPairingRequired = 10308,
|
|
102
|
+
/**
|
|
103
|
+
* Generic BLE connect failure where the OS dropped the specific reason. On
|
|
104
|
+
* macOS the noble native binding hardcodes "connection failed" (and a connect
|
|
105
|
+
* timeout) and discards the CoreBluetooth NSError, so the SDK cannot tell a
|
|
106
|
+
* stale bond from an out-of-range / unresponsive device. Surfaced as a
|
|
107
|
+
* generic "couldn't connect — check the device, re-pair if paired before".
|
|
108
|
+
* Distinct from BleBondInvalid (a *known* stale-bond signal, iOS/Android only)
|
|
109
|
+
* and BlePairingTimeout (the SMP bonding window).
|
|
110
|
+
*/
|
|
111
|
+
BleConnectFailed = 10309,
|
|
112
|
+
/**
|
|
113
|
+
* The user cancelled BLE pairing from the app while the connect was still
|
|
114
|
+
* waiting on the OS pairing window. Not a failure to report — the flow ends
|
|
115
|
+
* because they asked it to. Distinct from UserAborted (generic in-app cancel)
|
|
116
|
+
* so the pairing UI can close quietly instead of surfacing a connect error,
|
|
117
|
+
* and from BlePairingTimeout (the SMP window elapsed on its own).
|
|
118
|
+
*/
|
|
119
|
+
BlePairingCancelled = 10310,
|
|
120
|
+
PinInvalid = 10400,
|
|
121
|
+
PinCancelled = 10401,
|
|
122
|
+
PassphraseRejected = 10402,
|
|
123
|
+
/**
|
|
124
|
+
* The passphrase entered produced a different wallet (`passphraseState`) than
|
|
125
|
+
* the one the caller asked to operate on. Trezor-only: the host pins a wallet
|
|
126
|
+
* by its derived state and the SDK refuses to sign with a mismatched
|
|
127
|
+
* passphrase session. Surfaced by TrezorAdapter.getPassphraseState.
|
|
128
|
+
*/
|
|
129
|
+
PassphraseStateMismatch = 10403,
|
|
130
|
+
/**
|
|
131
|
+
* The two new-PIN entries did not match during set/change PIN. Only host-input
|
|
132
|
+
* models (Trezor Model One matrix) surface this; on-device-input models show
|
|
133
|
+
* the mismatch on the device and never return it.
|
|
134
|
+
*/
|
|
135
|
+
PinMismatch = 10404,
|
|
136
|
+
/** Chain app NOT INSTALLED on device. User must install via Ledger Live. */
|
|
137
|
+
AppNotInstalled = 10500,
|
|
138
|
+
WrongApp = 10501,
|
|
139
|
+
/** 0x911c Command code not supported — app predates current SDK. */
|
|
140
|
+
AppTooOld = 10502,
|
|
141
|
+
/** Not enough free storage for install/update; user must uninstall apps first. */
|
|
142
|
+
DeviceOutOfMemory = 10503,
|
|
143
|
+
/** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
|
|
144
|
+
* user has not enabled Blind signing on the device. */
|
|
145
|
+
EvmBlindSigningRequired = 11000,
|
|
146
|
+
/** 0x6984 Plugin not installed */
|
|
147
|
+
EvmClearSignPluginMissing = 11001,
|
|
148
|
+
/** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
|
|
149
|
+
EvmDataTooLarge = 11002,
|
|
150
|
+
/** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
|
|
151
|
+
EvmTxTypeNotSupported = 11003,
|
|
152
|
+
/** 0x6808 Blind signing disabled for this instruction. */
|
|
153
|
+
SolanaBlindSigningRequired = 11100,
|
|
154
|
+
/** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
|
|
155
|
+
TronCustomContractRequired = 11200,
|
|
156
|
+
/** 0x6a8b Transactions Data setting disabled. */
|
|
157
|
+
TronDataSigningRequired = 11201,
|
|
158
|
+
/** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
|
|
159
|
+
TronSignByHashRequired = 11202,
|
|
160
|
+
/** 0xb008 Wallet policy HMAC mismatch or not registered. */
|
|
161
|
+
BtcWalletPolicyHmacMismatch = 11300,
|
|
162
|
+
/** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
|
|
163
|
+
BtcUnexpectedState = 11301
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Device-level failures the SDK cannot self-recover from — affect the entire
|
|
167
|
+
* batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-
|
|
168
|
+
* skip in onboarding). Combined with `accounts.length === 0`, signals
|
|
169
|
+
* genuine orphan. Also reused as the batch-abort whitelist for HWK.
|
|
170
|
+
* Single source of truth.
|
|
171
|
+
*
|
|
172
|
+
* UserRejected (device-side reject) is included: pressing reject is an
|
|
173
|
+
* explicit "I don't consent" — continuing the batch to ask again on the
|
|
174
|
+
* next chain is harassment, not helpful.
|
|
175
|
+
*/
|
|
176
|
+
declare const ORPHAN_ELIGIBLE_ERROR_CODES: number[];
|
|
177
|
+
interface IHwkErrorPayload {
|
|
178
|
+
code: HardwareErrorCode;
|
|
179
|
+
message: string;
|
|
180
|
+
appName?: string;
|
|
181
|
+
_tag?: string;
|
|
182
|
+
params?: Record<string, unknown>;
|
|
183
|
+
}
|
|
184
|
+
type HwkError = Error & {
|
|
185
|
+
code: HardwareErrorCode;
|
|
186
|
+
appName?: string;
|
|
187
|
+
_tag?: string;
|
|
188
|
+
params?: Record<string, unknown>;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Canonical throwable for HWK adapters. Plain Error + canonical extra fields,
|
|
192
|
+
* shape-compatible with `rehydrateConnectorError` so locally-thrown and
|
|
193
|
+
* cross-boundary errors are indistinguishable to downstream classifiers
|
|
194
|
+
* (`err.code` / `err._tag` / `err.appName`). Do NOT mutate caught errors
|
|
195
|
+
* with `Object.assign` — construct a fresh one via this factory.
|
|
196
|
+
*/
|
|
197
|
+
declare function createHwkError(payload: IHwkErrorPayload): HwkError;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Enrich a hardware error message with actionable recovery hints.
|
|
201
|
+
* Shared across adapters (Ledger, Trezor, etc.).
|
|
202
|
+
*/
|
|
203
|
+
declare function enrichErrorMessage(code: HardwareErrorCode, originalMessage: string): string;
|
|
204
|
+
|
|
205
|
+
export { HardwareErrorCode, type HwkError, type IHwkErrorPayload, ORPHAN_ELIGIBLE_ERROR_CODES, createHwkError, enrichErrorMessage };
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
*/
|
|
24
|
+
declare enum HardwareErrorCode {
|
|
25
|
+
UnknownError = 10000,
|
|
26
|
+
UserRejected = 10001,
|
|
27
|
+
InvalidParams = 10002,
|
|
28
|
+
OperationTimeout = 10003,
|
|
29
|
+
MethodNotSupported = 10004,
|
|
30
|
+
/** User dismissed in-app cancel UI. Distinct from UserRejected (on-device). */
|
|
31
|
+
UserAborted = 10005,
|
|
32
|
+
DeviceNotFound = 10100,
|
|
33
|
+
DeviceDisconnected = 10101,
|
|
34
|
+
DeviceBusy = 10102,
|
|
35
|
+
DeviceLocked = 10103,
|
|
36
|
+
DeviceNotInitialized = 10104,
|
|
37
|
+
DeviceInBootloader = 10105,
|
|
38
|
+
DeviceMismatch = 10106,
|
|
39
|
+
/** Chain app wedged (e.g. Ledger BTC 0x6901). User must exit app on device. */
|
|
40
|
+
DeviceAppStuck = 10107,
|
|
41
|
+
/** Vendor (Ledger / Trezor) doesn't support the chain at all. */
|
|
42
|
+
ChainNotSupported = 10108,
|
|
43
|
+
/** Current operation supports only one connected device. */
|
|
44
|
+
DeviceOneDeviceOnly = 10109,
|
|
45
|
+
/**
|
|
46
|
+
* The device rejected the requested derivation path (Trezor Failure_DataError
|
|
47
|
+
* "Forbidden key path") — the path is non-standard or its index is outside the
|
|
48
|
+
* range the device's safety checks allow. Distinct from ChainNotSupported
|
|
49
|
+
* (whole chain) and MethodNotSupported (the operation/method itself).
|
|
50
|
+
*/
|
|
51
|
+
DevicePathForbidden = 10110,
|
|
52
|
+
/** Busy with our own in-flight request (queue guard / firmware Failure_Busy), not another app — wait and retry, don't close other apps. */
|
|
53
|
+
DeviceBusyInternal = 10111,
|
|
54
|
+
FirmwareTooOld = 10200,
|
|
55
|
+
FirmwareUpdateRequired = 10201,
|
|
56
|
+
TransportError = 10300,
|
|
57
|
+
BridgeNotFound = 10301,
|
|
58
|
+
TransportNotAvailable = 10302,
|
|
59
|
+
/**
|
|
60
|
+
* OS-level permission (Bluetooth / USB / etc.) — denied, blocked,
|
|
61
|
+
* unavailable, or dismissed. Consumers surface a single "please grant
|
|
62
|
+
* permission" toast and let the user retry manually.
|
|
63
|
+
*/
|
|
64
|
+
DevicePermissionDenied = 10303,
|
|
65
|
+
/**
|
|
66
|
+
* BLE SMP pairing did not complete within the GATT bonding window.
|
|
67
|
+
* GATT connected but the device didn't acknowledge SMP — typically
|
|
68
|
+
* because the user didn't confirm the passkey on the device, or the
|
|
69
|
+
* device went out of range mid-pairing. Distinct from OperationTimeout
|
|
70
|
+
* (generic) and from DeviceLocked (Secure Element actually locked).
|
|
71
|
+
*/
|
|
72
|
+
BlePairingTimeout = 10304,
|
|
73
|
+
/** Remote network failure reaching a vendor's servers (HTTP/WS). Distinct from TransportError (local USB/BLE link). */
|
|
74
|
+
NetworkError = 10305,
|
|
75
|
+
/**
|
|
76
|
+
* Host-managed pairing handshake failed (Trezor THP). The device rejected the
|
|
77
|
+
* pairing exchange — e.g. CodeEntry: the user mistyped the code shown on the
|
|
78
|
+
* device, so the CPace tag didn't match ("Unexpected Code Entry Tag").
|
|
79
|
+
* Recoverable: the user re-pairs and re-enters the code. Distinct from
|
|
80
|
+
* BlePairingTimeout (BLE SMP bonding window) and UserRejected (on-device
|
|
81
|
+
* reject button).
|
|
82
|
+
*/
|
|
83
|
+
ThpPairingFailed = 10306,
|
|
84
|
+
/**
|
|
85
|
+
* The OS-level BLE bond is stale/invalid, so the device rejected link
|
|
86
|
+
* encryption: Android GATT_INSUF_AUTHENTICATION (status 5) or iOS "Peer
|
|
87
|
+
* removed pairing information". Happens after the device is wiped/re-flashed
|
|
88
|
+
* or unpaired elsewhere while the host still holds an old bond. The SDK cannot
|
|
89
|
+
* remove an OS bond — the user must forget the device in system Bluetooth
|
|
90
|
+
* settings and re-pair. Distinct from BlePairingTimeout (SMP window) and
|
|
91
|
+
* ThpPairingFailed (THP code mismatch).
|
|
92
|
+
*/
|
|
93
|
+
BleBondInvalid = 10307,
|
|
94
|
+
/**
|
|
95
|
+
* A stored THP pairing credential was rejected by the device during the
|
|
96
|
+
* handshake (device returned completion `state=0`), so the autoconnect session
|
|
97
|
+
* could not be established. The SDK discards the stale credential; recovery is
|
|
98
|
+
* a fresh pairing. Distinct from ThpPairingFailed (user mistyped the code
|
|
99
|
+
* during an *active* pairing) and BleBondInvalid (OS-level BLE bond).
|
|
100
|
+
*/
|
|
101
|
+
ThpPairingRequired = 10308,
|
|
102
|
+
/**
|
|
103
|
+
* Generic BLE connect failure where the OS dropped the specific reason. On
|
|
104
|
+
* macOS the noble native binding hardcodes "connection failed" (and a connect
|
|
105
|
+
* timeout) and discards the CoreBluetooth NSError, so the SDK cannot tell a
|
|
106
|
+
* stale bond from an out-of-range / unresponsive device. Surfaced as a
|
|
107
|
+
* generic "couldn't connect — check the device, re-pair if paired before".
|
|
108
|
+
* Distinct from BleBondInvalid (a *known* stale-bond signal, iOS/Android only)
|
|
109
|
+
* and BlePairingTimeout (the SMP bonding window).
|
|
110
|
+
*/
|
|
111
|
+
BleConnectFailed = 10309,
|
|
112
|
+
/**
|
|
113
|
+
* The user cancelled BLE pairing from the app while the connect was still
|
|
114
|
+
* waiting on the OS pairing window. Not a failure to report — the flow ends
|
|
115
|
+
* because they asked it to. Distinct from UserAborted (generic in-app cancel)
|
|
116
|
+
* so the pairing UI can close quietly instead of surfacing a connect error,
|
|
117
|
+
* and from BlePairingTimeout (the SMP window elapsed on its own).
|
|
118
|
+
*/
|
|
119
|
+
BlePairingCancelled = 10310,
|
|
120
|
+
PinInvalid = 10400,
|
|
121
|
+
PinCancelled = 10401,
|
|
122
|
+
PassphraseRejected = 10402,
|
|
123
|
+
/**
|
|
124
|
+
* The passphrase entered produced a different wallet (`passphraseState`) than
|
|
125
|
+
* the one the caller asked to operate on. Trezor-only: the host pins a wallet
|
|
126
|
+
* by its derived state and the SDK refuses to sign with a mismatched
|
|
127
|
+
* passphrase session. Surfaced by TrezorAdapter.getPassphraseState.
|
|
128
|
+
*/
|
|
129
|
+
PassphraseStateMismatch = 10403,
|
|
130
|
+
/**
|
|
131
|
+
* The two new-PIN entries did not match during set/change PIN. Only host-input
|
|
132
|
+
* models (Trezor Model One matrix) surface this; on-device-input models show
|
|
133
|
+
* the mismatch on the device and never return it.
|
|
134
|
+
*/
|
|
135
|
+
PinMismatch = 10404,
|
|
136
|
+
/** Chain app NOT INSTALLED on device. User must install via Ledger Live. */
|
|
137
|
+
AppNotInstalled = 10500,
|
|
138
|
+
WrongApp = 10501,
|
|
139
|
+
/** 0x911c Command code not supported — app predates current SDK. */
|
|
140
|
+
AppTooOld = 10502,
|
|
141
|
+
/** Not enough free storage for install/update; user must uninstall apps first. */
|
|
142
|
+
DeviceOutOfMemory = 10503,
|
|
143
|
+
/** 0x6a80 Invalid data — observed on blindSignTransactionFallback when the
|
|
144
|
+
* user has not enabled Blind signing on the device. */
|
|
145
|
+
EvmBlindSigningRequired = 11000,
|
|
146
|
+
/** 0x6984 Plugin not installed */
|
|
147
|
+
EvmClearSignPluginMissing = 11001,
|
|
148
|
+
/** 0x6a84 Insufficient memory (typical on Nano S with large calldata) */
|
|
149
|
+
EvmDataTooLarge = 11002,
|
|
150
|
+
/** 0x6501 TransactionType not supported (app too old for EIP-1559 / blob / 7702) */
|
|
151
|
+
EvmTxTypeNotSupported = 11003,
|
|
152
|
+
/** 0x6808 Blind signing disabled for this instruction. */
|
|
153
|
+
SolanaBlindSigningRequired = 11100,
|
|
154
|
+
/** 0x6a8d Custom Contracts setting disabled (blocks TRC-20 etc.). */
|
|
155
|
+
TronCustomContractRequired = 11200,
|
|
156
|
+
/** 0x6a8b Transactions Data setting disabled. */
|
|
157
|
+
TronDataSigningRequired = 11201,
|
|
158
|
+
/** 0x6a8c Sign by Hash setting disabled (hash-signing fallback). */
|
|
159
|
+
TronSignByHashRequired = 11202,
|
|
160
|
+
/** 0xb008 Wallet policy HMAC mismatch or not registered. */
|
|
161
|
+
BtcWalletPolicyHmacMismatch = 11300,
|
|
162
|
+
/** 0xb007 Aborted due to unexpected state (malformed PSBT / missing UTXO). */
|
|
163
|
+
BtcUnexpectedState = 11301
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Device-level failures the SDK cannot self-recover from — affect the entire
|
|
167
|
+
* batch (vs per-chain failures like AppNotInstalled / WrongApp which soft-
|
|
168
|
+
* skip in onboarding). Combined with `accounts.length === 0`, signals
|
|
169
|
+
* genuine orphan. Also reused as the batch-abort whitelist for HWK.
|
|
170
|
+
* Single source of truth.
|
|
171
|
+
*
|
|
172
|
+
* UserRejected (device-side reject) is included: pressing reject is an
|
|
173
|
+
* explicit "I don't consent" — continuing the batch to ask again on the
|
|
174
|
+
* next chain is harassment, not helpful.
|
|
175
|
+
*/
|
|
176
|
+
declare const ORPHAN_ELIGIBLE_ERROR_CODES: number[];
|
|
177
|
+
interface IHwkErrorPayload {
|
|
178
|
+
code: HardwareErrorCode;
|
|
179
|
+
message: string;
|
|
180
|
+
appName?: string;
|
|
181
|
+
_tag?: string;
|
|
182
|
+
params?: Record<string, unknown>;
|
|
183
|
+
}
|
|
184
|
+
type HwkError = Error & {
|
|
185
|
+
code: HardwareErrorCode;
|
|
186
|
+
appName?: string;
|
|
187
|
+
_tag?: string;
|
|
188
|
+
params?: Record<string, unknown>;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Canonical throwable for HWK adapters. Plain Error + canonical extra fields,
|
|
192
|
+
* shape-compatible with `rehydrateConnectorError` so locally-thrown and
|
|
193
|
+
* cross-boundary errors are indistinguishable to downstream classifiers
|
|
194
|
+
* (`err.code` / `err._tag` / `err.appName`). Do NOT mutate caught errors
|
|
195
|
+
* with `Object.assign` — construct a fresh one via this factory.
|
|
196
|
+
*/
|
|
197
|
+
declare function createHwkError(payload: IHwkErrorPayload): HwkError;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Enrich a hardware error message with actionable recovery hints.
|
|
201
|
+
* Shared across adapters (Ledger, Trezor, etc.).
|
|
202
|
+
*/
|
|
203
|
+
declare function enrichErrorMessage(code: HardwareErrorCode, originalMessage: string): string;
|
|
204
|
+
|
|
205
|
+
export { HardwareErrorCode, type HwkError, type IHwkErrorPayload, ORPHAN_ELIGIBLE_ERROR_CODES, createHwkError, enrichErrorMessage };
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkSK7ZF33Jjs = require('./chunk-SK7ZF33J.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.HardwareErrorCode = _chunkSK7ZF33Jjs.HardwareErrorCode; exports.ORPHAN_ELIGIBLE_ERROR_CODES = _chunkSK7ZF33Jjs.ORPHAN_ELIGIBLE_ERROR_CODES; exports.createHwkError = _chunkSK7ZF33Jjs.createHwkError; exports.enrichErrorMessage = _chunkSK7ZF33Jjs.enrichErrorMessage;
|
|
13
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/hardware-js-sdk/hardware-js-sdk/packages/hwk-adapter-core/dist/errors.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACA;AACF,+QAAC","file":"/home/runner/work/hardware-js-sdk/hardware-js-sdk/packages/hwk-adapter-core/dist/errors.js"}
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HardwareErrorCode,
|
|
3
|
+
ORPHAN_ELIGIBLE_ERROR_CODES,
|
|
4
|
+
createHwkError,
|
|
5
|
+
enrichErrorMessage
|
|
6
|
+
} from "./chunk-67BP77GT.mjs";
|
|
7
|
+
export {
|
|
8
|
+
HardwareErrorCode,
|
|
9
|
+
ORPHAN_ELIGIBLE_ERROR_CODES,
|
|
10
|
+
createHwkError,
|
|
11
|
+
enrichErrorMessage
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|