@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.mjs
CHANGED
|
@@ -615,6 +615,7 @@ function keystoneBtcParamsFailure(params) {
|
|
|
615
615
|
}
|
|
616
616
|
return void 0;
|
|
617
617
|
}
|
|
618
|
+
var KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS = 24;
|
|
618
619
|
var KEYSTONE_USB_REATTACH_PROBE_ATTEMPTS = 4;
|
|
619
620
|
var KEYSTONE_USB_REATTACH_PROBE_INTERVAL_MS = 500;
|
|
620
621
|
var CHAIN_TYPE_BY_CHAIN = {
|
|
@@ -1774,7 +1775,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1774
1775
|
}
|
|
1775
1776
|
if (this._forcedTransport !== "qr" && !routedToQr && record?.usbSessionId) {
|
|
1776
1777
|
return {
|
|
1777
|
-
access: { channel: "usb", usbSessionId: record.usbSessionId },
|
|
1778
|
+
access: { channel: "usb", usbSessionId: record.usbSessionId, qrFallback: {} },
|
|
1778
1779
|
masterFingerprint: record.masterFingerprint
|
|
1779
1780
|
};
|
|
1780
1781
|
}
|
|
@@ -1785,6 +1786,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1785
1786
|
});
|
|
1786
1787
|
}
|
|
1787
1788
|
const schemas = Array.from(requestedByKey.values());
|
|
1789
|
+
if (schemas.length > KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS) {
|
|
1790
|
+
throw createHwkError2({
|
|
1791
|
+
code: HardwareErrorCode2.QrRequestTooLarge,
|
|
1792
|
+
message: `Keystone accepts at most ${KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS} account paths per QR request; this one needs ${schemas.length}`,
|
|
1793
|
+
params: { limit: KEYSTONE_MAX_KEY_DERIVATION_SCHEMAS, requested: schemas.length }
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1788
1796
|
const requestUr = this.urEngine.buildKeyDerivationRequest({
|
|
1789
1797
|
schemas: schemas.map((schema) => keySchema(schema.hwkChain, schema.path)),
|
|
1790
1798
|
origin: this._origin
|
|
@@ -2045,7 +2053,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2045
2053
|
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
|
|
2046
2054
|
* and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
|
|
2047
2055
|
*/
|
|
2048
|
-
async _resolveUr(record, requestUr, animated, operationId, signal, operationName) {
|
|
2056
|
+
async _resolveUr(record, requestUr, animated, operationId, signal, operationName, qrFallback) {
|
|
2049
2057
|
const releaseOperationRetention = isHardwareOperationId2(operationId) ? this._operations.retain(operationId) : void 0;
|
|
2050
2058
|
try {
|
|
2051
2059
|
return await this._resolveUrWithRoute(
|
|
@@ -2054,13 +2062,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2054
2062
|
animated,
|
|
2055
2063
|
operationId,
|
|
2056
2064
|
signal,
|
|
2057
|
-
operationName
|
|
2065
|
+
operationName,
|
|
2066
|
+
qrFallback
|
|
2058
2067
|
);
|
|
2059
2068
|
} finally {
|
|
2060
2069
|
releaseOperationRetention?.();
|
|
2061
2070
|
}
|
|
2062
2071
|
}
|
|
2063
|
-
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName) {
|
|
2072
|
+
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName, qrFallback) {
|
|
2064
2073
|
let record = callerRecord;
|
|
2065
2074
|
let interactionRoute;
|
|
2066
2075
|
if (isHardwareOperationId2(operationId)) {
|
|
@@ -2104,6 +2113,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2104
2113
|
const { origin: usbErrorOrigin, code: usbErrorCode } = usbError;
|
|
2105
2114
|
if (usbErrorCode === HardwareErrorCode2.PayloadTooLarge && usbErrorOrigin !== "device") {
|
|
2106
2115
|
if (!interactionRoute && !this._forcedTransport) {
|
|
2116
|
+
if (!await this._confirmQrFallback(signal, qrFallback)) {
|
|
2117
|
+
throw createHwkError2({
|
|
2118
|
+
code: HardwareErrorCode2.UserAborted,
|
|
2119
|
+
message: "User declined to show the request too large for USB as a QR code"
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2107
2122
|
const displayDevice2 = toDeviceInfo(record);
|
|
2108
2123
|
return this._requestQrAndAwaitResponse(displayDevice2, { ...requestUr, animated }, signal);
|
|
2109
2124
|
}
|
|
@@ -2208,7 +2223,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2208
2223
|
const useSinglePathUsbExport = operationConnectionType ? operationConnectionType === "usb" : this._forcedTransport === "usb" || this._forcedTransport !== "qr" && Boolean(existingRecord?.usbSessionId);
|
|
2209
2224
|
const schemas = [keySchema(hwkChain, syncPath)];
|
|
2210
2225
|
const requestUr = this.urEngine.buildKeyDerivationRequest({ schemas, origin: this._origin });
|
|
2211
|
-
const responseUr = await this._resolveUr(
|
|
2226
|
+
const responseUr = await this._resolveUr(
|
|
2227
|
+
existingRecord,
|
|
2228
|
+
requestUr,
|
|
2229
|
+
false,
|
|
2230
|
+
connectId,
|
|
2231
|
+
signal,
|
|
2232
|
+
void 0,
|
|
2233
|
+
bundle?.channel === "usb" ? bundle.qrFallback : void 0
|
|
2234
|
+
);
|
|
2212
2235
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2213
2236
|
const parsed = this.urEngine.parseAccountResponse(responseUr);
|
|
2214
2237
|
const account = requireExportedPath(parsed, syncPath);
|
|
@@ -2294,6 +2317,37 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2294
2317
|
signal.removeEventListener("abort", onAbort);
|
|
2295
2318
|
}
|
|
2296
2319
|
}
|
|
2320
|
+
/**
|
|
2321
|
+
* Asks whether a request too large for USB may be shown as a QR. A timeout or an unanswered
|
|
2322
|
+
* prompt reads as no; a cancelled call keeps its own error.
|
|
2323
|
+
*/
|
|
2324
|
+
async _confirmQrFallback(signal, choice) {
|
|
2325
|
+
if (choice?.confirmed !== void 0) return choice.confirmed;
|
|
2326
|
+
const requestType = UI_REQUEST.REQUEST_QR_FALLBACK_CONFIRM;
|
|
2327
|
+
const operationId = this._activeOperationId();
|
|
2328
|
+
const release = operationId ? this._operations.retain(operationId) : void 0;
|
|
2329
|
+
try {
|
|
2330
|
+
const waitPromise = this._uiRegistry.wait(requestType, {
|
|
2331
|
+
operationId
|
|
2332
|
+
});
|
|
2333
|
+
this.emitter.emit(requestType, {
|
|
2334
|
+
type: requestType,
|
|
2335
|
+
payload: { vendor: "keystone", operationId }
|
|
2336
|
+
});
|
|
2337
|
+
let confirmed = false;
|
|
2338
|
+
try {
|
|
2339
|
+
confirmed = Boolean(
|
|
2340
|
+
(await this._awaitQrResponse(requestType, waitPromise, signal))?.confirmed
|
|
2341
|
+
);
|
|
2342
|
+
} catch (error) {
|
|
2343
|
+
if (signal.aborted) throw error;
|
|
2344
|
+
}
|
|
2345
|
+
if (choice) choice.confirmed = confirmed;
|
|
2346
|
+
return confirmed;
|
|
2347
|
+
} finally {
|
|
2348
|
+
release?.();
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2297
2351
|
/** Shows `data` for the device to scan, or with no `data` asks the host to scan the device. */
|
|
2298
2352
|
async _requestQrAndAwaitResponse(device, data, signal) {
|
|
2299
2353
|
const requestType = data ? UI_REQUEST.REQUEST_QR_DISPLAY : UI_REQUEST.REQUEST_QR_SCAN;
|