@onekeyfe/hwk-keystone-adapter 1.2.8-alpha.112 → 1.2.8-alpha.114
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 +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +59 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -220,6 +220,11 @@ type BundleAccess = {
|
|
|
220
220
|
} | {
|
|
221
221
|
channel: 'usb';
|
|
222
222
|
usbSessionId: string;
|
|
223
|
+
qrFallback: QrFallbackChoice;
|
|
224
|
+
};
|
|
225
|
+
/** The answer to "show it as a QR?" for a request USB cannot carry; a bundle asks only once. */
|
|
226
|
+
type QrFallbackChoice = {
|
|
227
|
+
confirmed?: boolean;
|
|
223
228
|
};
|
|
224
229
|
interface ImportFromQrOptions {
|
|
225
230
|
/**
|
|
@@ -406,6 +411,11 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
406
411
|
* a cancel reach the wait before the QR timeout.
|
|
407
412
|
*/
|
|
408
413
|
private _awaitQrResponse;
|
|
414
|
+
/**
|
|
415
|
+
* Asks whether a request too large for USB may be shown as a QR. A timeout or an unanswered
|
|
416
|
+
* prompt reads as no; a cancelled call keeps its own error.
|
|
417
|
+
*/
|
|
418
|
+
private _confirmQrFallback;
|
|
409
419
|
/** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
|
|
410
420
|
private _requestQrAndAwaitResponse;
|
|
411
421
|
private _callUsbResolveUr;
|
package/dist/index.d.ts
CHANGED
|
@@ -220,6 +220,11 @@ type BundleAccess = {
|
|
|
220
220
|
} | {
|
|
221
221
|
channel: 'usb';
|
|
222
222
|
usbSessionId: string;
|
|
223
|
+
qrFallback: QrFallbackChoice;
|
|
224
|
+
};
|
|
225
|
+
/** The answer to "show it as a QR?" for a request USB cannot carry; a bundle asks only once. */
|
|
226
|
+
type QrFallbackChoice = {
|
|
227
|
+
confirmed?: boolean;
|
|
223
228
|
};
|
|
224
229
|
interface ImportFromQrOptions {
|
|
225
230
|
/**
|
|
@@ -406,6 +411,11 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
406
411
|
* a cancel reach the wait before the QR timeout.
|
|
407
412
|
*/
|
|
408
413
|
private _awaitQrResponse;
|
|
414
|
+
/**
|
|
415
|
+
* Asks whether a request too large for USB may be shown as a QR. A timeout or an unanswered
|
|
416
|
+
* prompt reads as no; a cancelled call keeps its own error.
|
|
417
|
+
*/
|
|
418
|
+
private _confirmQrFallback;
|
|
409
419
|
/** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
|
|
410
420
|
private _requestQrAndAwaitResponse;
|
|
411
421
|
private _callUsbResolveUr;
|
package/dist/index.js
CHANGED
|
@@ -607,6 +607,7 @@ function keystoneBtcParamsFailure(params) {
|
|
|
607
607
|
}
|
|
608
608
|
return void 0;
|
|
609
609
|
}
|
|
610
|
+
var KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS = 24;
|
|
610
611
|
var KEYSTONE_USB_REATTACH_PROBE_ATTEMPTS = 4;
|
|
611
612
|
var KEYSTONE_USB_REATTACH_PROBE_INTERVAL_MS = 500;
|
|
612
613
|
var CHAIN_TYPE_BY_CHAIN = {
|
|
@@ -1766,7 +1767,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1766
1767
|
}
|
|
1767
1768
|
if (this._forcedTransport !== "qr" && !routedToQr && record?.usbSessionId) {
|
|
1768
1769
|
return {
|
|
1769
|
-
access: { channel: "usb", usbSessionId: record.usbSessionId },
|
|
1770
|
+
access: { channel: "usb", usbSessionId: record.usbSessionId, qrFallback: {} },
|
|
1770
1771
|
masterFingerprint: record.masterFingerprint
|
|
1771
1772
|
};
|
|
1772
1773
|
}
|
|
@@ -1777,6 +1778,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1777
1778
|
});
|
|
1778
1779
|
}
|
|
1779
1780
|
const schemas = Array.from(requestedByKey.values());
|
|
1781
|
+
if (schemas.length > KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS) {
|
|
1782
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1783
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.QrRequestTooLarge,
|
|
1784
|
+
message: `Keystone accepts at most ${KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS} account paths per QR request; this one needs ${schemas.length}`,
|
|
1785
|
+
params: { limit: KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS, requested: schemas.length }
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1780
1788
|
const requestUr = this.urEngine.buildKeyDerivationRequest({
|
|
1781
1789
|
schemas: schemas.map((schema) => keySchema(schema.hwkChain, schema.path)),
|
|
1782
1790
|
origin: this._origin
|
|
@@ -2037,7 +2045,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2037
2045
|
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
|
|
2038
2046
|
* and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
|
|
2039
2047
|
*/
|
|
2040
|
-
async _resolveUr(record, requestUr, animated, operationId, signal, operationName) {
|
|
2048
|
+
async _resolveUr(record, requestUr, animated, operationId, signal, operationName, qrFallback) {
|
|
2041
2049
|
const releaseOperationRetention = (0, import_hwk_adapter_core3.isHardwareOperationId)(operationId) ? this._operations.retain(operationId) : void 0;
|
|
2042
2050
|
try {
|
|
2043
2051
|
return await this._resolveUrWithRoute(
|
|
@@ -2046,13 +2054,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2046
2054
|
animated,
|
|
2047
2055
|
operationId,
|
|
2048
2056
|
signal,
|
|
2049
|
-
operationName
|
|
2057
|
+
operationName,
|
|
2058
|
+
qrFallback
|
|
2050
2059
|
);
|
|
2051
2060
|
} finally {
|
|
2052
2061
|
releaseOperationRetention?.();
|
|
2053
2062
|
}
|
|
2054
2063
|
}
|
|
2055
|
-
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName) {
|
|
2064
|
+
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName, qrFallback) {
|
|
2056
2065
|
let record = callerRecord;
|
|
2057
2066
|
let interactionRoute;
|
|
2058
2067
|
if ((0, import_hwk_adapter_core3.isHardwareOperationId)(operationId)) {
|
|
@@ -2096,6 +2105,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2096
2105
|
const { origin: usbErrorOrigin, code: usbErrorCode } = usbError;
|
|
2097
2106
|
if (usbErrorCode === import_hwk_adapter_core3.HardwareErrorCode.PayloadTooLarge && usbErrorOrigin !== "device") {
|
|
2098
2107
|
if (!interactionRoute && !this._forcedTransport) {
|
|
2108
|
+
if (!await this._confirmQrFallback(signal, qrFallback)) {
|
|
2109
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2110
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UserAborted,
|
|
2111
|
+
message: "User declined to show the request too large for USB as a QR code"
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2099
2114
|
const displayDevice2 = toDeviceInfo(record);
|
|
2100
2115
|
return this._requestQrAndAwaitResponse(displayDevice2, { ...requestUr, animated }, signal);
|
|
2101
2116
|
}
|
|
@@ -2200,7 +2215,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2200
2215
|
const useSinglePathUsbExport = operationConnectionType ? operationConnectionType === "usb" : this._forcedTransport === "usb" || this._forcedTransport !== "qr" && Boolean(existingRecord?.usbSessionId);
|
|
2201
2216
|
const schemas = [keySchema(hwkChain, syncPath)];
|
|
2202
2217
|
const requestUr = this.urEngine.buildKeyDerivationRequest({ schemas, origin: this._origin });
|
|
2203
|
-
const responseUr = await this._resolveUr(
|
|
2218
|
+
const responseUr = await this._resolveUr(
|
|
2219
|
+
existingRecord,
|
|
2220
|
+
requestUr,
|
|
2221
|
+
false,
|
|
2222
|
+
connectId,
|
|
2223
|
+
signal,
|
|
2224
|
+
void 0,
|
|
2225
|
+
bundle?.channel === "usb" ? bundle.qrFallback : void 0
|
|
2226
|
+
);
|
|
2204
2227
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2205
2228
|
const parsed = this.urEngine.parseAccountResponse(responseUr);
|
|
2206
2229
|
const account = requireExportedPath(parsed, syncPath);
|
|
@@ -2286,6 +2309,37 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2286
2309
|
signal.removeEventListener("abort", onAbort);
|
|
2287
2310
|
}
|
|
2288
2311
|
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Asks whether a request too large for USB may be shown as a QR. A timeout or an unanswered
|
|
2314
|
+
* prompt reads as no; a cancelled call keeps its own error.
|
|
2315
|
+
*/
|
|
2316
|
+
async _confirmQrFallback(signal, choice) {
|
|
2317
|
+
if (choice?.confirmed !== void 0) return choice.confirmed;
|
|
2318
|
+
const requestType = import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_FALLBACK_CONFIRM;
|
|
2319
|
+
const operationId = this._activeOperationId();
|
|
2320
|
+
const release = operationId ? this._operations.retain(operationId) : void 0;
|
|
2321
|
+
try {
|
|
2322
|
+
const waitPromise = this._uiRegistry.wait(requestType, {
|
|
2323
|
+
operationId
|
|
2324
|
+
});
|
|
2325
|
+
this.emitter.emit(requestType, {
|
|
2326
|
+
type: requestType,
|
|
2327
|
+
payload: { vendor: "keystone", operationId }
|
|
2328
|
+
});
|
|
2329
|
+
let confirmed = false;
|
|
2330
|
+
try {
|
|
2331
|
+
confirmed = Boolean(
|
|
2332
|
+
(await this._awaitQrResponse(requestType, waitPromise, signal))?.confirmed
|
|
2333
|
+
);
|
|
2334
|
+
} catch (error) {
|
|
2335
|
+
if (signal.aborted) throw error;
|
|
2336
|
+
}
|
|
2337
|
+
if (choice) choice.confirmed = confirmed;
|
|
2338
|
+
return confirmed;
|
|
2339
|
+
} finally {
|
|
2340
|
+
release?.();
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2289
2343
|
/** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
|
|
2290
2344
|
async _requestQrAndAwaitResponse(device, data, signal) {
|
|
2291
2345
|
const requestType = data ? import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_DISPLAY : import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_SCAN;
|