@onekeyfe/hwk-keystone-adapter 1.2.8-alpha.119 → 1.2.8-alpha.121
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -404,7 +404,7 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
404
404
|
* a leaf path, so it is cut to the account path Keystone expects.
|
|
405
405
|
*/
|
|
406
406
|
private _ensureWalletKnown;
|
|
407
|
-
private
|
|
407
|
+
private _assertQrChainSupported;
|
|
408
408
|
/** Only an operation id supplied to the running call owns its UI prompts. */
|
|
409
409
|
private _activeOperationId;
|
|
410
410
|
/** Routes are keyed by connectId; a job key may be the bare master fingerprint. */
|
package/dist/index.d.ts
CHANGED
|
@@ -404,7 +404,7 @@ declare class KeystoneAdapter implements IHardwareWallet {
|
|
|
404
404
|
* a leaf path, so it is cut to the account path Keystone expects.
|
|
405
405
|
*/
|
|
406
406
|
private _ensureWalletKnown;
|
|
407
|
-
private
|
|
407
|
+
private _assertQrChainSupported;
|
|
408
408
|
/** Only an operation id supplied to the running call owns its UI prompts. */
|
|
409
409
|
private _activeOperationId;
|
|
410
410
|
/** Routes are keyed by connectId; a job key may be the bare master fingerprint. */
|
package/dist/index.js
CHANGED
|
@@ -222,7 +222,7 @@ function relativeHdPath(relativeDerivePath) {
|
|
|
222
222
|
}
|
|
223
223
|
return `m/${segments.join("/")}`;
|
|
224
224
|
}
|
|
225
|
-
var FIRMWARE_VERSION = /^\d{1,4}(\.\d{1,4}){1,3}(-[0-9A-Za-z
|
|
225
|
+
var FIRMWARE_VERSION = /^\d{1,4}(\.\d{1,4}){1,3}(-[0-9A-Za-z.-]{1,20})?$/;
|
|
226
226
|
var DEVICE_TEXT = /^[^\p{Cc}\p{Cf}]{1,64}$/u;
|
|
227
227
|
function deviceText(value, pattern) {
|
|
228
228
|
return typeof value === "string" && pattern.test(value) ? value : void 0;
|
|
@@ -330,7 +330,9 @@ var KeystoneUrEngine = class {
|
|
|
330
330
|
}
|
|
331
331
|
const byPath = /* @__PURE__ */ new Map();
|
|
332
332
|
for (const account of parsed.accounts) {
|
|
333
|
-
if (!/^m(?:\/\d+')+(?:\/\d+)*$/.test(account.path) || account.path.slice(2).split("/").some(
|
|
333
|
+
if (!/^m(?:\/\d+')+(?:\/\d+)*$/.test(account.path) || account.path.slice(2).split("/").some(
|
|
334
|
+
(segment) => Number(segment.endsWith("'") ? segment.slice(0, -1) : segment) >= BIP32_HARDENED_OFFSET
|
|
335
|
+
)) {
|
|
334
336
|
throw new Error("Account export has an unsupported derivation path");
|
|
335
337
|
}
|
|
336
338
|
let identity = account.publicKey;
|
|
@@ -553,31 +555,6 @@ var import_bs58 = __toESM(require("bs58"));
|
|
|
553
555
|
var import_uuid2 = require("uuid");
|
|
554
556
|
var import_hwk_adapter_core3 = require("@onekeyfe/hwk-adapter-core");
|
|
555
557
|
|
|
556
|
-
// src/adapter/firmwareCapabilities.ts
|
|
557
|
-
var MULTI_COIN = {
|
|
558
|
-
variant: "multi-coin",
|
|
559
|
-
supportedChains: ["btc", "evm", "sol", "tron"]
|
|
560
|
-
};
|
|
561
|
-
var BITCOIN_ONLY = {
|
|
562
|
-
variant: "bitcoin-only",
|
|
563
|
-
supportedChains: ["btc"]
|
|
564
|
-
};
|
|
565
|
-
var CYPHERPUNK = {
|
|
566
|
-
variant: "cypherpunk",
|
|
567
|
-
// Firmware support alone is insufficient: this adapter has no Zcash/Monero methods yet.
|
|
568
|
-
supportedChains: ["btc"]
|
|
569
|
-
};
|
|
570
|
-
function getKeystoneFirmwareProfile(firmwareVersion) {
|
|
571
|
-
if (!firmwareVersion || firmwareVersion === "0.0.0") return void 0;
|
|
572
|
-
const version = /^\d{1,4}(?:\.\d{1,4}){1,3}(?:-([a-z0-9.-]{1,40}))?$/i.exec(firmwareVersion);
|
|
573
|
-
if (!version) return void 0;
|
|
574
|
-
const suffix = version[1]?.toUpperCase();
|
|
575
|
-
if (!suffix) return MULTI_COIN;
|
|
576
|
-
if (suffix === "C" || suffix === "CYPHERPUNK" || suffix === "CYPHERPUNK-B") return CYPHERPUNK;
|
|
577
|
-
if (suffix === "B" || suffix === "BTC" || suffix === "BTC-ONLY") return BITCOIN_ONLY;
|
|
578
|
-
return void 0;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
558
|
// src/adapter/pathUtils.ts
|
|
582
559
|
function normalizePath(path) {
|
|
583
560
|
const trimmed = path.trim();
|
|
@@ -653,7 +630,6 @@ function toDeviceInfo(record) {
|
|
|
653
630
|
}
|
|
654
631
|
function toDeviceInfoForConnection(record, connectionType) {
|
|
655
632
|
const firmwareVersion = connectionType === "usb" ? record.usbFirmwareVersion : record.deviceVersion;
|
|
656
|
-
const firmware = connectionType === "usb" ? getKeystoneFirmwareProfile(firmwareVersion) : void 0;
|
|
657
633
|
let availableChannels = ["qr"];
|
|
658
634
|
if (record.usbSessionId) {
|
|
659
635
|
availableChannels = record.qrSynced ? ["qr", "usb"] : ["usb"];
|
|
@@ -667,8 +643,7 @@ function toDeviceInfoForConnection(record, connectionType) {
|
|
|
667
643
|
connectId: record.connectId,
|
|
668
644
|
connectionType,
|
|
669
645
|
capabilities: {
|
|
670
|
-
...CAPABILITIES
|
|
671
|
-
...firmware ? { supportedChains: [...firmware.supportedChains] } : {}
|
|
646
|
+
...CAPABILITIES
|
|
672
647
|
},
|
|
673
648
|
raw: {
|
|
674
649
|
availableChannels,
|
|
@@ -689,6 +664,31 @@ function placeholderDeviceInfo() {
|
|
|
689
664
|
};
|
|
690
665
|
}
|
|
691
666
|
|
|
667
|
+
// src/adapter/firmwareCapabilities.ts
|
|
668
|
+
var MULTI_COIN = {
|
|
669
|
+
variant: "multi-coin",
|
|
670
|
+
supportedChains: ["btc", "evm", "sol", "tron"]
|
|
671
|
+
};
|
|
672
|
+
var BITCOIN_ONLY = {
|
|
673
|
+
variant: "bitcoin-only",
|
|
674
|
+
supportedChains: ["btc"]
|
|
675
|
+
};
|
|
676
|
+
var CYPHERPUNK = {
|
|
677
|
+
variant: "cypherpunk",
|
|
678
|
+
// Firmware support alone is insufficient: this adapter has no Zcash/Monero methods yet.
|
|
679
|
+
supportedChains: ["btc"]
|
|
680
|
+
};
|
|
681
|
+
function getKeystoneFirmwareProfile(firmwareVersion) {
|
|
682
|
+
if (!firmwareVersion || firmwareVersion === "0.0.0") return void 0;
|
|
683
|
+
const version = /^\d{1,4}(?:\.\d{1,4}){1,3}(?:-([a-z0-9.-]{1,40}))?$/i.exec(firmwareVersion);
|
|
684
|
+
if (!version) return void 0;
|
|
685
|
+
const suffix = version[1]?.toUpperCase();
|
|
686
|
+
if (!suffix) return MULTI_COIN;
|
|
687
|
+
if (suffix === "C" || suffix === "CYPHERPUNK" || suffix === "CYPHERPUNK-B") return CYPHERPUNK;
|
|
688
|
+
if (suffix === "B" || suffix === "BTC" || suffix === "BTC-ONLY") return BITCOIN_ONLY;
|
|
689
|
+
return void 0;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
692
|
// src/utils/queueKey.ts
|
|
693
693
|
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
694
694
|
var KEYSTONE_COLD_START_JOB_LABEL = "keystone-cold-start";
|
|
@@ -1491,7 +1491,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1491
1491
|
true,
|
|
1492
1492
|
connectId,
|
|
1493
1493
|
signal,
|
|
1494
|
-
"btc",
|
|
1495
1494
|
"btcSignPsbt"
|
|
1496
1495
|
);
|
|
1497
1496
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
@@ -1839,7 +1838,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1839
1838
|
true,
|
|
1840
1839
|
connectId,
|
|
1841
1840
|
signal,
|
|
1842
|
-
args.chain,
|
|
1843
1841
|
args.operationName
|
|
1844
1842
|
);
|
|
1845
1843
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
@@ -2208,7 +2206,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2208
2206
|
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session reattaches once
|
|
2209
2207
|
* and fails closed if that fails; otherwise a failed USB reattach leaves the call on QR.
|
|
2210
2208
|
*/
|
|
2211
|
-
async _resolveUr(record, requestUr, animated, operationId, signal,
|
|
2209
|
+
async _resolveUr(record, requestUr, animated, operationId, signal, operationName, qrFallback) {
|
|
2212
2210
|
const releaseOperationRetention = (0, import_hwk_adapter_core3.isHardwareOperationId)(operationId) ? this._operations.retain(operationId) : void 0;
|
|
2213
2211
|
try {
|
|
2214
2212
|
return await this._resolveUrWithRoute(
|
|
@@ -2217,7 +2215,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2217
2215
|
animated,
|
|
2218
2216
|
operationId,
|
|
2219
2217
|
signal,
|
|
2220
|
-
chain,
|
|
2221
2218
|
operationName,
|
|
2222
2219
|
qrFallback
|
|
2223
2220
|
);
|
|
@@ -2225,7 +2222,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2225
2222
|
releaseOperationRetention?.();
|
|
2226
2223
|
}
|
|
2227
2224
|
}
|
|
2228
|
-
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal,
|
|
2225
|
+
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName, qrFallback) {
|
|
2229
2226
|
let record = callerRecord;
|
|
2230
2227
|
let interactionRoute;
|
|
2231
2228
|
if ((0, import_hwk_adapter_core3.isHardwareOperationId)(operationId)) {
|
|
@@ -2258,7 +2255,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2258
2255
|
message: "USB channel is not connected for this Keystone wallet"
|
|
2259
2256
|
});
|
|
2260
2257
|
}
|
|
2261
|
-
this._assertChainSupported(record.usbFirmwareVersion, chain);
|
|
2262
2258
|
const result = await this._callUsbResolveUr(
|
|
2263
2259
|
this._usbConnector,
|
|
2264
2260
|
record.usbSessionId,
|
|
@@ -2382,7 +2378,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2382
2378
|
message: `Keystone did not return the requested derivation path (${syncPath})`
|
|
2383
2379
|
});
|
|
2384
2380
|
}
|
|
2385
|
-
this.
|
|
2381
|
+
this._assertQrChainSupported(bundle.firmwareVersion, hwkChain);
|
|
2386
2382
|
return { record: target.record, account: scanned };
|
|
2387
2383
|
}
|
|
2388
2384
|
if (bundle?.channel === "usb" && target.record?.usbSessionId !== bundle.usbSessionId) {
|
|
@@ -2405,7 +2401,6 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2405
2401
|
false,
|
|
2406
2402
|
connectId,
|
|
2407
2403
|
signal,
|
|
2408
|
-
hwkChain,
|
|
2409
2404
|
void 0,
|
|
2410
2405
|
bundle?.channel === "usb" ? bundle.qrFallback : void 0
|
|
2411
2406
|
);
|
|
@@ -2424,7 +2419,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2424
2419
|
}
|
|
2425
2420
|
record = existingRecord;
|
|
2426
2421
|
} else {
|
|
2427
|
-
this.
|
|
2422
|
+
this._assertQrChainSupported(parsed.deviceVersion, hwkChain);
|
|
2428
2423
|
record = this._upsertDeviceRecord(parsed);
|
|
2429
2424
|
}
|
|
2430
2425
|
return { record, account: { ...account, hwkChain } };
|
|
@@ -2447,15 +2442,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2447
2442
|
schemas: [keySchema(chain, accountPath)],
|
|
2448
2443
|
origin: this._origin
|
|
2449
2444
|
});
|
|
2450
|
-
const responseUr = await this._resolveUr(void 0, requestUr, false, connectId, signal
|
|
2445
|
+
const responseUr = await this._resolveUr(void 0, requestUr, false, connectId, signal);
|
|
2451
2446
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2452
2447
|
const parsed = responseUr.accountExport ? this.urEngine.parseAccountExport(responseUr) : this.urEngine.parseAccountResponse(responseUr);
|
|
2453
2448
|
requireExportedPath(parsed, normalizePath(accountPath), responseUr.accountExport);
|
|
2454
|
-
this.
|
|
2449
|
+
this._assertQrChainSupported(parsed.deviceVersion, chain);
|
|
2455
2450
|
const record = this._upsertDeviceRecord(parsed);
|
|
2456
2451
|
return { record };
|
|
2457
2452
|
}
|
|
2458
|
-
|
|
2453
|
+
_assertQrChainSupported(firmwareVersion, chain) {
|
|
2459
2454
|
const firmware = getKeystoneFirmwareProfile(firmwareVersion);
|
|
2460
2455
|
if (firmware && !firmware.supportedChains.includes(chain)) {
|
|
2461
2456
|
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
@@ -2507,15 +2502,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2507
2502
|
async _confirmQrFallback(signal, choice) {
|
|
2508
2503
|
if (choice?.confirmed !== void 0) return choice.confirmed;
|
|
2509
2504
|
const requestType = import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_FALLBACK_CONFIRM;
|
|
2505
|
+
const requestId = this._uiRegistry.createRequestId();
|
|
2510
2506
|
const operationId = this._activeOperationId();
|
|
2511
2507
|
const release = operationId ? this._operations.retain(operationId) : void 0;
|
|
2512
2508
|
try {
|
|
2513
2509
|
const waitPromise = this._uiRegistry.wait(requestType, {
|
|
2510
|
+
requestId,
|
|
2514
2511
|
operationId
|
|
2515
2512
|
});
|
|
2516
2513
|
this.emitter.emit(requestType, {
|
|
2517
2514
|
type: requestType,
|
|
2518
|
-
payload: { vendor: "keystone", operationId }
|
|
2515
|
+
payload: { vendor: "keystone", requestId, operationId }
|
|
2519
2516
|
});
|
|
2520
2517
|
let confirmed = false;
|
|
2521
2518
|
try {
|