@onekeyfe/hwk-keystone-adapter 1.2.5-alpha.0 → 1.2.5-alpha.1
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 +13 -19
- package/dist/index.d.ts +13 -19
- package/dist/index.js +279 -353
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -158
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -30,14 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
KEYSTONE_COLD_START_PATH: () => KEYSTONE_COLD_START_PATH,
|
|
33
34
|
KEYSTONE_WALLET_CONNECT_ID_PREFIX: () => KEYSTONE_WALLET_CONNECT_ID_PREFIX,
|
|
34
|
-
KEYSTONE_WALLET_ID_PATH: () => KEYSTONE_WALLET_ID_PATH,
|
|
35
35
|
KeystoneAdapter: () => KeystoneAdapter,
|
|
36
36
|
KeystoneUrEngine: () => KeystoneUrEngine,
|
|
37
37
|
accountKey: () => accountKey,
|
|
38
38
|
btcScriptTypeFromPath: () => btcScriptTypeFromPath,
|
|
39
39
|
createDeviceRecord: () => createDeviceRecord,
|
|
40
|
-
deriveKeystoneWalletId: () => deriveKeystoneWalletId,
|
|
41
40
|
normalizePath: () => normalizePath,
|
|
42
41
|
placeholderDeviceInfo: () => placeholderDeviceInfo,
|
|
43
42
|
splitAccountPath: () => splitAccountPath,
|
|
@@ -189,9 +188,10 @@ function requireSignatureBytes(hex, expectedBytes, chain) {
|
|
|
189
188
|
}
|
|
190
189
|
return hex;
|
|
191
190
|
}
|
|
191
|
+
var MISSING_MASTER_FINGERPRINT = "00000000";
|
|
192
192
|
function requireBip32MasterFingerprint(value) {
|
|
193
193
|
const fingerprint = (0, import_hwk_adapter_core.parseBip32MasterFingerprint)(value);
|
|
194
|
-
if (!fingerprint) {
|
|
194
|
+
if (!fingerprint || fingerprint === MISSING_MASTER_FINGERPRINT) {
|
|
195
195
|
throw new Error("Keystone master fingerprint must be exactly 4 bytes (8 hex characters)");
|
|
196
196
|
}
|
|
197
197
|
return fingerprint;
|
|
@@ -430,10 +430,7 @@ var KeystoneUrEngine = class {
|
|
|
430
430
|
// src/adapter/KeystoneAdapter.ts
|
|
431
431
|
var import_bs58 = __toESM(require("bs58"));
|
|
432
432
|
var import_uuid2 = require("uuid");
|
|
433
|
-
var
|
|
434
|
-
|
|
435
|
-
// src/adapter/deviceTable.ts
|
|
436
|
-
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
433
|
+
var import_hwk_adapter_core3 = require("@onekeyfe/hwk-adapter-core");
|
|
437
434
|
|
|
438
435
|
// src/adapter/pathUtils.ts
|
|
439
436
|
function normalizePath(path) {
|
|
@@ -479,31 +476,17 @@ var KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE = "Keystone BTC is limited to mainnet
|
|
|
479
476
|
|
|
480
477
|
// src/adapter/deviceTable.ts
|
|
481
478
|
var KEYSTONE_WALLET_CONNECT_ID_PREFIX = "keystone-wallet:";
|
|
482
|
-
var
|
|
483
|
-
function walletConnectId(
|
|
484
|
-
return `${KEYSTONE_WALLET_CONNECT_ID_PREFIX}${
|
|
479
|
+
var KEYSTONE_COLD_START_PATH = "m/44'/60'/0'";
|
|
480
|
+
function walletConnectId(masterFingerprint) {
|
|
481
|
+
return `${KEYSTONE_WALLET_CONNECT_ID_PREFIX}${masterFingerprint}`;
|
|
485
482
|
}
|
|
486
483
|
function accountKey(hwkChain, path) {
|
|
487
484
|
return `${hwkChain}:${normalizePath(path)}`;
|
|
488
485
|
}
|
|
489
|
-
function
|
|
490
|
-
const identityAccount = accounts.find(
|
|
491
|
-
(account) => normalizePath(account.path) === KEYSTONE_WALLET_ID_PATH
|
|
492
|
-
);
|
|
493
|
-
if (!identityAccount?.extendedPublicKey) {
|
|
494
|
-
throw new Error(
|
|
495
|
-
`Keystone identity response is missing the extended public key at ${KEYSTONE_WALLET_ID_PATH}`
|
|
496
|
-
);
|
|
497
|
-
}
|
|
498
|
-
return (0, import_hwk_adapter_core2.deriveWalletId)(
|
|
499
|
-
`keystone:secp256k1:${KEYSTONE_WALLET_ID_PATH}:${identityAccount.extendedPublicKey.trim()}`
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
function createDeviceRecord(walletId, masterFingerprint) {
|
|
486
|
+
function createDeviceRecord(masterFingerprint) {
|
|
503
487
|
return {
|
|
504
|
-
walletId,
|
|
505
488
|
masterFingerprint,
|
|
506
|
-
connectId: walletConnectId(
|
|
489
|
+
connectId: walletConnectId(masterFingerprint),
|
|
507
490
|
importedAt: Date.now()
|
|
508
491
|
};
|
|
509
492
|
}
|
|
@@ -518,7 +501,7 @@ function toDeviceInfo(record) {
|
|
|
518
501
|
model: record.model ?? "unknown",
|
|
519
502
|
modelName: record.model,
|
|
520
503
|
firmwareVersion: record.deviceVersion ?? "0.0.0",
|
|
521
|
-
deviceId: record.
|
|
504
|
+
deviceId: record.masterFingerprint,
|
|
522
505
|
connectId: record.connectId,
|
|
523
506
|
connectionType: record.usbSessionId ? "usb" : "qr",
|
|
524
507
|
capabilities: CAPABILITIES,
|
|
@@ -542,22 +525,22 @@ function placeholderDeviceInfo() {
|
|
|
542
525
|
}
|
|
543
526
|
|
|
544
527
|
// src/utils/queueKey.ts
|
|
545
|
-
var
|
|
528
|
+
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
546
529
|
var KEYSTONE_COLD_START_JOB_LABEL = "keystone-cold-start";
|
|
547
530
|
function keystoneQueueKey(connectId, deviceId) {
|
|
548
|
-
return (0,
|
|
531
|
+
return (0, import_hwk_adapter_core2.isHardwareOperationId)(connectId) ? connectId : deviceId || connectId || KEYSTONE_COLD_START_JOB_LABEL;
|
|
549
532
|
}
|
|
550
|
-
function
|
|
533
|
+
function keystoneMfpFromIdentifier(identifier) {
|
|
551
534
|
const value = identifier.startsWith(KEYSTONE_WALLET_CONNECT_ID_PREFIX) ? identifier.slice(KEYSTONE_WALLET_CONNECT_ID_PREFIX.length) : identifier;
|
|
552
|
-
return
|
|
535
|
+
return (0, import_hwk_adapter_core2.parseBip32MasterFingerprint)(value);
|
|
553
536
|
}
|
|
554
537
|
function keystoneCancelQueueKeys(identifiers) {
|
|
555
538
|
const keys = /* @__PURE__ */ new Set();
|
|
556
539
|
for (const identifier of identifiers) {
|
|
557
540
|
if (identifier) {
|
|
558
541
|
keys.add(identifier);
|
|
559
|
-
const
|
|
560
|
-
if (
|
|
542
|
+
const masterFingerprint = keystoneMfpFromIdentifier(identifier);
|
|
543
|
+
if (masterFingerprint) keys.add(masterFingerprint);
|
|
561
544
|
}
|
|
562
545
|
}
|
|
563
546
|
return keys;
|
|
@@ -567,7 +550,7 @@ function keystoneCancelQueueKeys(identifiers) {
|
|
|
567
550
|
var KEYSTONE_USB_REATTACH_PROBE_ATTEMPTS = 4;
|
|
568
551
|
var KEYSTONE_USB_REATTACH_PROBE_INTERVAL_MS = 500;
|
|
569
552
|
function resolveHardwareOperationTarget(positionalTargetId, operationId) {
|
|
570
|
-
return (0,
|
|
553
|
+
return (0, import_hwk_adapter_core3.resolveHardwareOperationTarget)(positionalTargetId, operationId, "keystone");
|
|
571
554
|
}
|
|
572
555
|
function keySchema(chain, path) {
|
|
573
556
|
return { path, curve: chain === "sol" ? "ed25519" : "secp256k1" };
|
|
@@ -579,9 +562,9 @@ function waitForKeystoneUsbReattachProbe() {
|
|
|
579
562
|
}
|
|
580
563
|
function buildCancelledFailure(signal) {
|
|
581
564
|
const reason = signal.reason;
|
|
582
|
-
const code = typeof reason?.code === "number" ? reason.code :
|
|
565
|
+
const code = typeof reason?.code === "number" ? reason.code : import_hwk_adapter_core3.HardwareErrorCode.UserAborted;
|
|
583
566
|
const message = typeof reason?.message === "string" ? reason.message : "";
|
|
584
|
-
return (0,
|
|
567
|
+
return (0, import_hwk_adapter_core3.failure)(code, message || "All-network get-address cancelled");
|
|
585
568
|
}
|
|
586
569
|
var BIP44_COIN_TYPE_TO_CHAIN = {
|
|
587
570
|
60: "evm",
|
|
@@ -599,17 +582,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
599
582
|
// No protocol-level cancel exists over Keystone USB, and QR has no transport
|
|
600
583
|
// to interrupt at all. Cancelling ends the wait, not the device's prompt.
|
|
601
584
|
this.cancelCapability = "stops-waiting";
|
|
602
|
-
this.emitter = new
|
|
585
|
+
this.emitter = new import_hwk_adapter_core3.TypedEventEmitter();
|
|
603
586
|
this._operationRoutes = /* @__PURE__ */ new Map();
|
|
604
|
-
this._operations = new
|
|
587
|
+
this._operations = new import_hwk_adapter_core3.OperationRegistry({
|
|
605
588
|
vendor: "keystone",
|
|
606
589
|
onEnded: (operation, reason) => {
|
|
607
590
|
const route = this._operationRoutes.get(operation.connectId);
|
|
608
591
|
if (route?.operationId === operation.operationId) {
|
|
609
592
|
this._operationRoutes.delete(operation.connectId);
|
|
610
593
|
}
|
|
611
|
-
this.emitter.emit(
|
|
612
|
-
type:
|
|
594
|
+
this.emitter.emit(import_hwk_adapter_core3.SDK.OPERATION_ENDED, {
|
|
595
|
+
type: import_hwk_adapter_core3.SDK.OPERATION_ENDED,
|
|
613
596
|
payload: { operationId: operation.operationId, reason }
|
|
614
597
|
});
|
|
615
598
|
if (reason === "timeout") {
|
|
@@ -617,7 +600,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
617
600
|
}
|
|
618
601
|
}
|
|
619
602
|
});
|
|
620
|
-
this._uiRegistry = new
|
|
603
|
+
this._uiRegistry = new import_hwk_adapter_core3.UiRequestRegistry();
|
|
621
604
|
this._devices = /* @__PURE__ */ new Map();
|
|
622
605
|
this._searchDeviceTargets = /* @__PURE__ */ new Map();
|
|
623
606
|
/** Serializes USB open/identity handshakes that run outside the job queue. */
|
|
@@ -634,10 +617,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
634
617
|
record.usbSessionId = void 0;
|
|
635
618
|
const info = toDeviceInfo(record);
|
|
636
619
|
if (record.qrSynced) {
|
|
637
|
-
this.emitter.emit(
|
|
620
|
+
this.emitter.emit(import_hwk_adapter_core3.DEVICE.CHANGED, { type: import_hwk_adapter_core3.DEVICE.CHANGED, payload: info });
|
|
638
621
|
} else {
|
|
639
|
-
this._devices.delete(record.
|
|
640
|
-
this.emitter.emit(
|
|
622
|
+
this._devices.delete(record.masterFingerprint);
|
|
623
|
+
this.emitter.emit(import_hwk_adapter_core3.DEVICE.DISCONNECT, { type: import_hwk_adapter_core3.DEVICE.DISCONNECT, payload: info });
|
|
641
624
|
}
|
|
642
625
|
};
|
|
643
626
|
this._handleUsbUiEvent = (event) => {
|
|
@@ -658,13 +641,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
658
641
|
operationId
|
|
659
642
|
});
|
|
660
643
|
const { book } = prefetched;
|
|
661
|
-
const itemDeviceId = deviceId || prefetched.
|
|
644
|
+
const itemDeviceId = deviceId || prefetched.masterFingerprint || "";
|
|
662
645
|
const scope = this._jobQueue.createCancelScope(
|
|
663
646
|
keystoneQueueKey(effectiveConnectId, itemDeviceId)
|
|
664
647
|
);
|
|
665
648
|
cancelScope = scope;
|
|
666
649
|
const cancelledIndexes = /* @__PURE__ */ new Set();
|
|
667
|
-
return await (0,
|
|
650
|
+
return await (0, import_hwk_adapter_core3.runAllNetworkGetAddress)({
|
|
668
651
|
connectId: effectiveConnectId,
|
|
669
652
|
deviceId: itemDeviceId,
|
|
670
653
|
params,
|
|
@@ -690,8 +673,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
690
673
|
case "tronGetAddress":
|
|
691
674
|
return this.tronGetAddress(effectiveConnectId, itemDeviceId, commonArgs, book);
|
|
692
675
|
default:
|
|
693
|
-
return (0,
|
|
694
|
-
|
|
676
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
677
|
+
import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
695
678
|
`Unsupported method: ${String(method)}`
|
|
696
679
|
);
|
|
697
680
|
}
|
|
@@ -707,7 +690,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
707
690
|
deviceIdentity: record ? {
|
|
708
691
|
vendor: "keystone",
|
|
709
692
|
type: "walletId",
|
|
710
|
-
value: record.
|
|
693
|
+
value: record.masterFingerprint
|
|
711
694
|
} : void 0
|
|
712
695
|
}
|
|
713
696
|
});
|
|
@@ -716,7 +699,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
716
699
|
// failures carry on with the next chain.
|
|
717
700
|
shouldAbortBundle: (response, { index }) => {
|
|
718
701
|
const { code } = response.payload ?? {};
|
|
719
|
-
return cancelledIndexes.has(index) || (0,
|
|
702
|
+
return cancelledIndexes.has(index) || (0, import_hwk_adapter_core3.isUserRefusal)(code) || (0, import_hwk_adapter_core3.isConnectionLost)(code);
|
|
720
703
|
}
|
|
721
704
|
});
|
|
722
705
|
} catch (err) {
|
|
@@ -728,7 +711,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
728
711
|
this._origin = options?.origin ?? "OneKey";
|
|
729
712
|
this._qrTimeoutMs = options?.qrTimeoutMs;
|
|
730
713
|
this.urEngine = new KeystoneUrEngine(this._origin);
|
|
731
|
-
this._jobQueue = new
|
|
714
|
+
this._jobQueue = new import_hwk_adapter_core3.DeviceJobQueue();
|
|
732
715
|
this._usbConnector = options?.usbConnector;
|
|
733
716
|
this._usbConnector?.on("device-disconnect", this._handleUsbDisconnect);
|
|
734
717
|
this._usbConnector?.on("ui-event", this._handleUsbUiEvent);
|
|
@@ -783,7 +766,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
783
766
|
}
|
|
784
767
|
const known = Array.from(this._devices.values()).map(toDeviceInfo);
|
|
785
768
|
if (options?.transportType === "qr") {
|
|
786
|
-
const searchTargetId = (0,
|
|
769
|
+
const searchTargetId = (0, import_hwk_adapter_core3.createHardwareSearchTargetId)("keystone");
|
|
787
770
|
this._searchDeviceTargets.set(searchTargetId, "qr");
|
|
788
771
|
return [
|
|
789
772
|
{
|
|
@@ -852,7 +835,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
852
835
|
const devices = await this.searchDevices(options);
|
|
853
836
|
return devices.map((device) => ({
|
|
854
837
|
searchTargetId: device.connectId,
|
|
855
|
-
// The
|
|
838
|
+
// The master fingerprint is known only after the USB/QR handshake.
|
|
856
839
|
searchTargetReusePolicy: "current-discovery",
|
|
857
840
|
vendor: device.vendor,
|
|
858
841
|
connectionType: device.connectionType,
|
|
@@ -891,15 +874,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
891
874
|
} else if (discoveredConnectionType === "usb") {
|
|
892
875
|
selectedConnectionType = "usb";
|
|
893
876
|
if (!this._usbConnector) {
|
|
894
|
-
return (0,
|
|
895
|
-
|
|
877
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
878
|
+
import_hwk_adapter_core3.HardwareErrorCode.TransportNotAvailable,
|
|
896
879
|
"No USB connector configured for this Keystone adapter"
|
|
897
880
|
);
|
|
898
881
|
}
|
|
899
882
|
connected = await this._connectUsb({}, searchTargetId, scope.signal);
|
|
900
|
-
} else if ((0,
|
|
901
|
-
return (0,
|
|
902
|
-
|
|
883
|
+
} else if ((0, import_hwk_adapter_core3.hasHardwareRuntimeIdPrefix)(searchTargetId)) {
|
|
884
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
885
|
+
import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
903
886
|
"Keystone search target has expired; search for devices again",
|
|
904
887
|
void 0,
|
|
905
888
|
void 0,
|
|
@@ -909,10 +892,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
909
892
|
const target = this._resolveTarget(searchTargetId);
|
|
910
893
|
if (target.record) {
|
|
911
894
|
selectedConnectionType = target.record.usbSessionId ? "usb" : "qr";
|
|
912
|
-
connected = (0,
|
|
895
|
+
connected = (0, import_hwk_adapter_core3.success)(toDeviceInfo(target.record));
|
|
913
896
|
} else if (!this._usbConnector) {
|
|
914
|
-
return (0,
|
|
915
|
-
|
|
897
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
898
|
+
import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
916
899
|
`Unknown Keystone device search target: ${searchTargetId}`
|
|
917
900
|
);
|
|
918
901
|
} else {
|
|
@@ -935,7 +918,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
935
918
|
operationId: operation.operationId,
|
|
936
919
|
connectionType: selectedConnectionType
|
|
937
920
|
});
|
|
938
|
-
return (0,
|
|
921
|
+
return (0, import_hwk_adapter_core3.success)(operation.operationId);
|
|
939
922
|
} catch (err) {
|
|
940
923
|
return this._errorToFailure(err);
|
|
941
924
|
} finally {
|
|
@@ -972,32 +955,32 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
972
955
|
}
|
|
973
956
|
getDeviceInfo(connectIdOrOperationId, deviceId) {
|
|
974
957
|
try {
|
|
975
|
-
const connectId = (0,
|
|
958
|
+
const connectId = (0, import_hwk_adapter_core3.isHardwareOperationId)(connectIdOrOperationId) ? this._operations.resolve(connectIdOrOperationId).connectId : connectIdOrOperationId;
|
|
976
959
|
const { record } = this._resolveTarget(connectId, deviceId);
|
|
977
960
|
if (!record) {
|
|
978
961
|
return Promise.resolve(
|
|
979
|
-
(0,
|
|
980
|
-
|
|
962
|
+
(0, import_hwk_adapter_core3.failure)(
|
|
963
|
+
import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
981
964
|
`Unknown Keystone device: ${connectId || deviceId}`
|
|
982
965
|
)
|
|
983
966
|
);
|
|
984
967
|
}
|
|
985
|
-
return Promise.resolve((0,
|
|
968
|
+
return Promise.resolve((0, import_hwk_adapter_core3.success)(toDeviceInfo(record)));
|
|
986
969
|
} catch (err) {
|
|
987
970
|
return Promise.resolve(this._errorToFailure(err));
|
|
988
971
|
}
|
|
989
972
|
}
|
|
990
973
|
cancel(connectId) {
|
|
991
974
|
let namedOperationConnectId;
|
|
992
|
-
if ((0,
|
|
975
|
+
if ((0, import_hwk_adapter_core3.isHardwareOperationId)(connectId)) {
|
|
993
976
|
try {
|
|
994
977
|
namedOperationConnectId = this._operations.resolve(connectId).connectId;
|
|
995
978
|
} catch {
|
|
996
979
|
return;
|
|
997
980
|
}
|
|
998
981
|
}
|
|
999
|
-
const reason = (0,
|
|
1000
|
-
code:
|
|
982
|
+
const reason = (0, import_hwk_adapter_core3.createHwkError)({
|
|
983
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UserAborted,
|
|
1001
984
|
message: "User aborted operation"
|
|
1002
985
|
});
|
|
1003
986
|
if (connectId) {
|
|
@@ -1009,7 +992,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1009
992
|
for (const key of queueKeys) {
|
|
1010
993
|
this._jobQueue.cancelActiveAndPending(key, reason);
|
|
1011
994
|
}
|
|
1012
|
-
const scopedOperationId = (0,
|
|
995
|
+
const scopedOperationId = (0, import_hwk_adapter_core3.isHardwareOperationId)(connectId) ? connectId : this._operationRouteForIdentifier(connectId)?.operationId;
|
|
1013
996
|
if (scopedOperationId) {
|
|
1014
997
|
this._uiRegistry.cancel(void 0, void 0, scopedOperationId);
|
|
1015
998
|
}
|
|
@@ -1021,19 +1004,21 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1021
1004
|
getChainFingerprint(connectId, deviceId, chain) {
|
|
1022
1005
|
try {
|
|
1023
1006
|
const target = this._resolveTarget(connectId, deviceId);
|
|
1024
|
-
const
|
|
1025
|
-
if (!
|
|
1007
|
+
const masterFingerprint = target.expectedMasterFingerprint;
|
|
1008
|
+
if (!masterFingerprint) {
|
|
1026
1009
|
return Promise.resolve(
|
|
1027
|
-
(0,
|
|
1010
|
+
(0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound, "Unknown Keystone wallet identity")
|
|
1028
1011
|
);
|
|
1029
1012
|
}
|
|
1030
|
-
return Promise.resolve(
|
|
1013
|
+
return Promise.resolve(
|
|
1014
|
+
(0, import_hwk_adapter_core3.success)((0, import_hwk_adapter_core3.deriveDeviceFingerprint)(`keystone:${chain}:${masterFingerprint}`))
|
|
1015
|
+
);
|
|
1031
1016
|
} catch (err) {
|
|
1032
1017
|
return Promise.resolve(this._errorToFailure(err));
|
|
1033
1018
|
}
|
|
1034
1019
|
}
|
|
1035
1020
|
uiResponse(response) {
|
|
1036
|
-
if (response.type ===
|
|
1021
|
+
if (response.type === import_hwk_adapter_core3.UI_RESPONSE.CANCEL) {
|
|
1037
1022
|
this.cancel();
|
|
1038
1023
|
return;
|
|
1039
1024
|
}
|
|
@@ -1057,7 +1042,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1057
1042
|
responseUr = await this._requestQrScanAndAwaitResponse(displayDevice, signal);
|
|
1058
1043
|
} else {
|
|
1059
1044
|
const requestUr = this.urEngine.buildKeyDerivationRequest({
|
|
1060
|
-
schemas: [keySchema("evm",
|
|
1045
|
+
schemas: [keySchema("evm", KEYSTONE_COLD_START_PATH)],
|
|
1061
1046
|
origin: this._origin
|
|
1062
1047
|
});
|
|
1063
1048
|
responseUr = await this._requestQrDisplayAndAwaitResponse(
|
|
@@ -1069,7 +1054,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1069
1054
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1070
1055
|
const parsed = this.urEngine.parseAccountResponse(responseUr);
|
|
1071
1056
|
const record = this._upsertDeviceRecord(parsed);
|
|
1072
|
-
return (0,
|
|
1057
|
+
return (0, import_hwk_adapter_core3.success)(toDeviceInfo(record));
|
|
1073
1058
|
});
|
|
1074
1059
|
} catch (err) {
|
|
1075
1060
|
return this._errorToFailure(err);
|
|
@@ -1083,13 +1068,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1083
1068
|
if (!operationTarget.success) return operationTarget;
|
|
1084
1069
|
const connectId = operationTarget.payload.targetId;
|
|
1085
1070
|
const deviceId = deviceIdArg ?? void 0;
|
|
1086
|
-
if (!params) return (0,
|
|
1071
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmGetAddress requires params");
|
|
1087
1072
|
if (!params.path)
|
|
1088
|
-
return (0,
|
|
1073
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmGetAddress requires params.path");
|
|
1089
1074
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1090
1075
|
if (!relativeDerivePath) {
|
|
1091
|
-
return (0,
|
|
1092
|
-
|
|
1076
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1077
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1093
1078
|
"evmGetAddress requires a full leaf path, e.g. m/44'/60'/0'/0/0"
|
|
1094
1079
|
);
|
|
1095
1080
|
}
|
|
@@ -1103,7 +1088,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1103
1088
|
book
|
|
1104
1089
|
);
|
|
1105
1090
|
const address = this.urEngine.deriveEvmAddressFromXpub(xpub, relativeDerivePath);
|
|
1106
|
-
return (0,
|
|
1091
|
+
return (0, import_hwk_adapter_core3.success)({ address, path: normalizePath(params.path) });
|
|
1107
1092
|
});
|
|
1108
1093
|
}
|
|
1109
1094
|
async evmSignTransaction(connectIdArg, deviceIdArg, params) {
|
|
@@ -1112,17 +1097,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1112
1097
|
const connectId = operationTarget.payload.targetId;
|
|
1113
1098
|
const deviceId = deviceIdArg ?? void 0;
|
|
1114
1099
|
if (!params)
|
|
1115
|
-
return (0,
|
|
1100
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmSignTransaction requires params");
|
|
1116
1101
|
if (!params.path) {
|
|
1117
|
-
return (0,
|
|
1102
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmSignTransaction requires params.path");
|
|
1118
1103
|
}
|
|
1119
1104
|
if (!("serializedTx" in params) || typeof params.serializedTx !== "string" || !params.serializedTx) {
|
|
1120
|
-
return (0,
|
|
1121
|
-
|
|
1105
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1106
|
+
import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
1122
1107
|
"Keystone only signs a fully RLP-serialized transaction (params.serializedTx) \u2014 structured-field signing is not supported"
|
|
1123
1108
|
);
|
|
1124
1109
|
}
|
|
1125
|
-
const rawTxHex = (0,
|
|
1110
|
+
const rawTxHex = (0, import_hwk_adapter_core3.stripHex)(params.serializedTx);
|
|
1126
1111
|
const path = normalizePath(params.path);
|
|
1127
1112
|
const dataType = parseInt(rawTxHex.slice(0, 2), 16) < 192 ? "typedTransaction" : "transaction";
|
|
1128
1113
|
return this._signWithWallet({
|
|
@@ -1141,9 +1126,9 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1141
1126
|
}),
|
|
1142
1127
|
parseResponse: (ur) => this.urEngine.parseEthSignature(ur),
|
|
1143
1128
|
toPayload: (sig) => ({
|
|
1144
|
-
v: (0,
|
|
1145
|
-
r: (0,
|
|
1146
|
-
s: (0,
|
|
1129
|
+
v: (0, import_hwk_adapter_core3.ensure0x)(sig.v),
|
|
1130
|
+
r: (0, import_hwk_adapter_core3.ensure0x)(sig.r),
|
|
1131
|
+
s: (0, import_hwk_adapter_core3.ensure0x)(sig.s)
|
|
1147
1132
|
})
|
|
1148
1133
|
});
|
|
1149
1134
|
}
|
|
@@ -1152,14 +1137,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1152
1137
|
if (!operationTarget.success) return operationTarget;
|
|
1153
1138
|
const connectId = operationTarget.payload.targetId;
|
|
1154
1139
|
const deviceId = deviceIdArg ?? void 0;
|
|
1155
|
-
if (!params) return (0,
|
|
1140
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmSignMessage requires params");
|
|
1156
1141
|
if (!params.path || params.message === void 0) {
|
|
1157
|
-
return (0,
|
|
1158
|
-
|
|
1142
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1143
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1159
1144
|
"evmSignMessage requires params.path and params.message"
|
|
1160
1145
|
);
|
|
1161
1146
|
}
|
|
1162
|
-
const messageHex = params.hex ? (0,
|
|
1147
|
+
const messageHex = params.hex ? (0, import_hwk_adapter_core3.stripHex)(params.message) : Buffer.from(params.message, "utf8").toString("hex");
|
|
1163
1148
|
const path = normalizePath(params.path);
|
|
1164
1149
|
return this._signWithWallet({
|
|
1165
1150
|
connectId,
|
|
@@ -1176,7 +1161,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1176
1161
|
origin: this._origin
|
|
1177
1162
|
}),
|
|
1178
1163
|
parseResponse: (ur) => this.urEngine.parseEthSignature(ur),
|
|
1179
|
-
toPayload: (sig) => ({ signature: (0,
|
|
1164
|
+
toPayload: (sig) => ({ signature: (0, import_hwk_adapter_core3.ensure0x)(sig.r + sig.s + sig.v) })
|
|
1180
1165
|
});
|
|
1181
1166
|
}
|
|
1182
1167
|
async evmSignTypedData(connectIdArg, deviceIdArg, params) {
|
|
@@ -1185,13 +1170,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1185
1170
|
const connectId = operationTarget.payload.targetId;
|
|
1186
1171
|
const deviceId = deviceIdArg ?? void 0;
|
|
1187
1172
|
if (!params)
|
|
1188
|
-
return (0,
|
|
1173
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmSignTypedData requires params");
|
|
1189
1174
|
if (!params.path) {
|
|
1190
|
-
return (0,
|
|
1175
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "evmSignTypedData requires params.path");
|
|
1191
1176
|
}
|
|
1192
1177
|
if (params.mode === "hash") {
|
|
1193
|
-
return (0,
|
|
1194
|
-
|
|
1178
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1179
|
+
import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
1195
1180
|
"Keystone always displays the full EIP-712 payload for on-device review \u2014 pre-hashed signing is not supported"
|
|
1196
1181
|
);
|
|
1197
1182
|
}
|
|
@@ -1215,7 +1200,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1215
1200
|
origin: this._origin
|
|
1216
1201
|
}),
|
|
1217
1202
|
parseResponse: (ur) => this.urEngine.parseEthSignature(ur),
|
|
1218
|
-
toPayload: (sig) => ({ signature: (0,
|
|
1203
|
+
toPayload: (sig) => ({ signature: (0, import_hwk_adapter_core3.ensure0x)(sig.r + sig.s + sig.v) })
|
|
1219
1204
|
});
|
|
1220
1205
|
}
|
|
1221
1206
|
// ---------------------------------------------------------------------------
|
|
@@ -1227,13 +1212,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1227
1212
|
if (!operationTarget.success) return operationTarget;
|
|
1228
1213
|
const connectId = operationTarget.payload.targetId;
|
|
1229
1214
|
const deviceId = deviceIdArg ?? void 0;
|
|
1230
|
-
if (!params) return (0,
|
|
1215
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcGetAddress requires params");
|
|
1231
1216
|
if (!params.path)
|
|
1232
|
-
return (0,
|
|
1217
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcGetAddress requires params.path");
|
|
1233
1218
|
const scriptType = btcScriptTypeFromPath(params.path);
|
|
1234
1219
|
if (!scriptType) {
|
|
1235
|
-
return (0,
|
|
1236
|
-
|
|
1220
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1221
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1237
1222
|
"btcGetAddress requires a path whose purpose is 44'/49'/84'/86' (P2PKH/P2SH-P2WPKH/P2WPKH/P2TR)"
|
|
1238
1223
|
);
|
|
1239
1224
|
}
|
|
@@ -1246,13 +1231,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1246
1231
|
const normalizedPath = normalizePath(params.path);
|
|
1247
1232
|
const { accountPath, relativeDerivePath } = splitAccountPath(normalizedPath);
|
|
1248
1233
|
if (!relativeDerivePath) {
|
|
1249
|
-
return (0,
|
|
1250
|
-
|
|
1234
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1235
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1251
1236
|
"btcGetAddress requires a full leaf path, e.g. m/84'/0'/0'/0/0"
|
|
1252
1237
|
);
|
|
1253
1238
|
}
|
|
1254
1239
|
if (!isKeystoneSignableBtcAccountPath(accountPath)) {
|
|
1255
|
-
return (0,
|
|
1240
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1256
1241
|
}
|
|
1257
1242
|
return this._runJob(connectId, deviceId, async (signal) => {
|
|
1258
1243
|
const xpub = await this._fetchAccountXpub(
|
|
@@ -1264,7 +1249,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1264
1249
|
book
|
|
1265
1250
|
);
|
|
1266
1251
|
const address = this.urEngine.deriveBtcAddressFromXpub(xpub, relativeDerivePath, scriptType);
|
|
1267
|
-
return (0,
|
|
1252
|
+
return (0, import_hwk_adapter_core3.success)({ address, path: normalizedPath });
|
|
1268
1253
|
});
|
|
1269
1254
|
}
|
|
1270
1255
|
/**
|
|
@@ -1276,18 +1261,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1276
1261
|
if (!operationTarget.success) return operationTarget;
|
|
1277
1262
|
const connectId = operationTarget.payload.targetId;
|
|
1278
1263
|
const deviceId = deviceIdArg ?? void 0;
|
|
1279
|
-
if (!params) return (0,
|
|
1264
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcGetPublicKey requires params");
|
|
1280
1265
|
if (!params.path)
|
|
1281
|
-
return (0,
|
|
1266
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcGetPublicKey requires params.path");
|
|
1282
1267
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1283
1268
|
if (relativeDerivePath) {
|
|
1284
|
-
return (0,
|
|
1285
|
-
|
|
1269
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1270
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1286
1271
|
"btcGetPublicKey requires an account path, e.g. m/84'/0'/0' (not a leaf path)"
|
|
1287
1272
|
);
|
|
1288
1273
|
}
|
|
1289
1274
|
if (!isKeystoneSignableBtcAccountPath(accountPath)) {
|
|
1290
|
-
return (0,
|
|
1275
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1291
1276
|
}
|
|
1292
1277
|
return this._runJob(connectId, deviceId, async (signal) => {
|
|
1293
1278
|
const xpub = await this._fetchAccountXpub(
|
|
@@ -1299,7 +1284,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1299
1284
|
book
|
|
1300
1285
|
);
|
|
1301
1286
|
const meta = this.urEngine.parseXpubMeta(xpub);
|
|
1302
|
-
return (0,
|
|
1287
|
+
return (0, import_hwk_adapter_core3.success)({
|
|
1303
1288
|
xpub,
|
|
1304
1289
|
publicKey: meta.publicKey,
|
|
1305
1290
|
chainCode: meta.chainCode,
|
|
@@ -1320,18 +1305,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1320
1305
|
if (!operationTarget.success) return operationTarget;
|
|
1321
1306
|
const connectId = operationTarget.payload.targetId;
|
|
1322
1307
|
const deviceId = deviceIdArg ?? void 0;
|
|
1323
|
-
if (!params) return (0,
|
|
1308
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params");
|
|
1324
1309
|
if (!params.psbt)
|
|
1325
|
-
return (0,
|
|
1310
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params.psbt");
|
|
1326
1311
|
if (!params.path)
|
|
1327
|
-
return (0,
|
|
1312
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params.path");
|
|
1328
1313
|
if (!isKeystoneSignableBtcAccountPath(splitAccountPath(params.path).accountPath)) {
|
|
1329
|
-
return (0,
|
|
1314
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1330
1315
|
}
|
|
1331
1316
|
return this._runJob(connectId, deviceId, async (signal) => {
|
|
1332
1317
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1333
1318
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1334
|
-
const requestUr = this.urEngine.buildBtcPsbtRequest((0,
|
|
1319
|
+
const requestUr = this.urEngine.buildBtcPsbtRequest((0, import_hwk_adapter_core3.stripHex)(params.psbt));
|
|
1335
1320
|
const responseUr = await this._resolveUr(
|
|
1336
1321
|
record,
|
|
1337
1322
|
requestUr,
|
|
@@ -1342,7 +1327,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1342
1327
|
);
|
|
1343
1328
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1344
1329
|
const signedPsbt = this.urEngine.parseBtcPsbt(responseUr);
|
|
1345
|
-
return (0,
|
|
1330
|
+
return (0, import_hwk_adapter_core3.success)({ signedPsbt });
|
|
1346
1331
|
});
|
|
1347
1332
|
}
|
|
1348
1333
|
async btcSignMessage(connectIdArg, deviceIdArg, params) {
|
|
@@ -1350,17 +1335,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1350
1335
|
if (!operationTarget.success) return operationTarget;
|
|
1351
1336
|
const connectId = operationTarget.payload.targetId;
|
|
1352
1337
|
const deviceId = deviceIdArg ?? void 0;
|
|
1353
|
-
if (!params) return (0,
|
|
1338
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "btcSignMessage requires params");
|
|
1354
1339
|
if (!params.path || params.message === void 0) {
|
|
1355
|
-
return (0,
|
|
1356
|
-
|
|
1340
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1341
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1357
1342
|
"btcSignMessage requires params.path and params.message"
|
|
1358
1343
|
);
|
|
1359
1344
|
}
|
|
1360
|
-
const messageHex = params.hex ? (0,
|
|
1345
|
+
const messageHex = params.hex ? (0, import_hwk_adapter_core3.stripHex)(params.message) : Buffer.from(params.message, "utf8").toString("hex");
|
|
1361
1346
|
const path = normalizePath(params.path);
|
|
1362
1347
|
if (!isKeystoneSignableBtcAccountPath(splitAccountPath(path).accountPath)) {
|
|
1363
|
-
return (0,
|
|
1348
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1364
1349
|
}
|
|
1365
1350
|
return this._signWithWallet({
|
|
1366
1351
|
connectId,
|
|
@@ -1384,7 +1369,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1384
1369
|
const deviceId = deviceIdArg ?? void 0;
|
|
1385
1370
|
return this._runJob(connectId, deviceId, async (signal) => {
|
|
1386
1371
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1387
|
-
return (0,
|
|
1372
|
+
return (0, import_hwk_adapter_core3.success)({ masterFingerprint: record.masterFingerprint });
|
|
1388
1373
|
});
|
|
1389
1374
|
}
|
|
1390
1375
|
// ---------------------------------------------------------------------------
|
|
@@ -1395,15 +1380,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1395
1380
|
if (!operationTarget.success) return operationTarget;
|
|
1396
1381
|
const connectId = operationTarget.payload.targetId;
|
|
1397
1382
|
const deviceId = deviceIdArg ?? void 0;
|
|
1398
|
-
if (!params) return (0,
|
|
1383
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "solGetAddress requires params");
|
|
1399
1384
|
if (!params.path)
|
|
1400
|
-
return (0,
|
|
1385
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "solGetAddress requires params.path");
|
|
1401
1386
|
const path = normalizePath(params.path);
|
|
1402
1387
|
return this._runJob(connectId, deviceId, async (signal) => {
|
|
1403
1388
|
const { account } = await this._fetchAccount(connectId, deviceId, "sol", path, signal, book);
|
|
1404
1389
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1405
1390
|
const address = import_bs58.default.encode(Buffer.from(account.publicKey, "hex"));
|
|
1406
|
-
return (0,
|
|
1391
|
+
return (0, import_hwk_adapter_core3.success)({ address, path });
|
|
1407
1392
|
});
|
|
1408
1393
|
}
|
|
1409
1394
|
async solSignTransaction(connectIdArg, deviceIdArg, params) {
|
|
@@ -1412,10 +1397,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1412
1397
|
const connectId = operationTarget.payload.targetId;
|
|
1413
1398
|
const deviceId = deviceIdArg ?? void 0;
|
|
1414
1399
|
if (!params)
|
|
1415
|
-
return (0,
|
|
1400
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "solSignTransaction requires params");
|
|
1416
1401
|
if (!params.path || !params.serializedTx) {
|
|
1417
|
-
return (0,
|
|
1418
|
-
|
|
1402
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1403
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1419
1404
|
"solSignTransaction requires params.path and params.serializedTx"
|
|
1420
1405
|
);
|
|
1421
1406
|
}
|
|
@@ -1427,7 +1412,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1427
1412
|
operationName: "solSignTransaction",
|
|
1428
1413
|
buildRequest: (requestId, xfp) => this.urEngine.buildSolSignRequest({
|
|
1429
1414
|
requestId,
|
|
1430
|
-
unsignedPayloadHex: (0,
|
|
1415
|
+
unsignedPayloadHex: (0, import_hwk_adapter_core3.stripHex)(params.serializedTx),
|
|
1431
1416
|
dataType: "transaction",
|
|
1432
1417
|
path,
|
|
1433
1418
|
xfp,
|
|
@@ -1442,10 +1427,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1442
1427
|
if (!operationTarget.success) return operationTarget;
|
|
1443
1428
|
const connectId = operationTarget.payload.targetId;
|
|
1444
1429
|
const deviceId = deviceIdArg ?? void 0;
|
|
1445
|
-
if (!params) return (0,
|
|
1430
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "solSignMessage requires params");
|
|
1446
1431
|
if (!params.path || !params.message) {
|
|
1447
|
-
return (0,
|
|
1448
|
-
|
|
1432
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1433
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1449
1434
|
"solSignMessage requires params.path and params.message"
|
|
1450
1435
|
);
|
|
1451
1436
|
}
|
|
@@ -1457,7 +1442,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1457
1442
|
operationName: "solSignMessage",
|
|
1458
1443
|
buildRequest: (requestId, xfp) => this.urEngine.buildSolSignRequest({
|
|
1459
1444
|
requestId,
|
|
1460
|
-
unsignedPayloadHex: (0,
|
|
1445
|
+
unsignedPayloadHex: (0, import_hwk_adapter_core3.stripHex)(params.message),
|
|
1461
1446
|
dataType: "message",
|
|
1462
1447
|
path,
|
|
1463
1448
|
xfp,
|
|
@@ -1476,13 +1461,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1476
1461
|
if (!operationTarget.success) return operationTarget;
|
|
1477
1462
|
const connectId = operationTarget.payload.targetId;
|
|
1478
1463
|
const deviceId = deviceIdArg ?? void 0;
|
|
1479
|
-
if (!params) return (0,
|
|
1464
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronGetAddress requires params");
|
|
1480
1465
|
if (!params.path)
|
|
1481
|
-
return (0,
|
|
1466
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronGetAddress requires params.path");
|
|
1482
1467
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1483
1468
|
if (!relativeDerivePath) {
|
|
1484
|
-
return (0,
|
|
1485
|
-
|
|
1469
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1470
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1486
1471
|
"tronGetAddress requires a full leaf path, e.g. m/44'/195'/0'/0/0"
|
|
1487
1472
|
);
|
|
1488
1473
|
}
|
|
@@ -1496,7 +1481,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1496
1481
|
book
|
|
1497
1482
|
);
|
|
1498
1483
|
const address = this.urEngine.deriveTronAddressFromXpub(xpub, relativeDerivePath);
|
|
1499
|
-
return (0,
|
|
1484
|
+
return (0, import_hwk_adapter_core3.success)({ address, path: normalizePath(params.path) });
|
|
1500
1485
|
});
|
|
1501
1486
|
}
|
|
1502
1487
|
async tronSignTransaction(connectIdArg, deviceIdArg, params) {
|
|
@@ -1505,17 +1490,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1505
1490
|
const connectId = operationTarget.payload.targetId;
|
|
1506
1491
|
const deviceId = deviceIdArg ?? void 0;
|
|
1507
1492
|
if (!params)
|
|
1508
|
-
return (0,
|
|
1493
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronSignTransaction requires params");
|
|
1509
1494
|
if (!params.path) {
|
|
1510
|
-
return (0,
|
|
1495
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronSignTransaction requires params.path");
|
|
1511
1496
|
}
|
|
1512
1497
|
if (!params.rawTxHex) {
|
|
1513
|
-
return (0,
|
|
1514
|
-
|
|
1498
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1499
|
+
import_hwk_adapter_core3.HardwareErrorCode.InvalidParams,
|
|
1515
1500
|
"Keystone only signs a fully protobuf-serialized TRON transaction (params.rawTxHex) \u2014 the Trezor-style structured contract fields have no equivalent here"
|
|
1516
1501
|
);
|
|
1517
1502
|
}
|
|
1518
|
-
const rawTxHex = (0,
|
|
1503
|
+
const rawTxHex = (0, import_hwk_adapter_core3.stripHex)(params.rawTxHex);
|
|
1519
1504
|
const path = normalizePath(params.path);
|
|
1520
1505
|
return this._signWithWallet({
|
|
1521
1506
|
connectId,
|
|
@@ -1539,20 +1524,20 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1539
1524
|
if (!operationTarget.success) return operationTarget;
|
|
1540
1525
|
const connectId = operationTarget.payload.targetId;
|
|
1541
1526
|
const deviceId = deviceIdArg ?? void 0;
|
|
1542
|
-
if (!params) return (0,
|
|
1527
|
+
if (!params) return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronSignMessage requires params");
|
|
1543
1528
|
if (!params.path) {
|
|
1544
|
-
return (0,
|
|
1529
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronSignMessage requires params.path");
|
|
1545
1530
|
}
|
|
1546
1531
|
if (!params.messageHex) {
|
|
1547
|
-
return (0,
|
|
1532
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.InvalidParams, "tronSignMessage requires params.messageHex");
|
|
1548
1533
|
}
|
|
1549
1534
|
if (params.messageType !== "V2") {
|
|
1550
|
-
return (0,
|
|
1551
|
-
|
|
1535
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1536
|
+
import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
1552
1537
|
'Keystone signs TRON messages as TIP-191 signMessageV2 only (messageType: "V2")'
|
|
1553
1538
|
);
|
|
1554
1539
|
}
|
|
1555
|
-
const messageHex = (0,
|
|
1540
|
+
const messageHex = (0, import_hwk_adapter_core3.stripHex)(params.messageHex);
|
|
1556
1541
|
const path = normalizePath(params.path);
|
|
1557
1542
|
return this._signWithWallet({
|
|
1558
1543
|
connectId,
|
|
@@ -1592,8 +1577,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1592
1577
|
);
|
|
1593
1578
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1594
1579
|
if (!account.extendedPublicKey) {
|
|
1595
|
-
throw (0,
|
|
1596
|
-
code:
|
|
1580
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1581
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
1597
1582
|
message: "Keystone did not return an extended public key for this account path"
|
|
1598
1583
|
});
|
|
1599
1584
|
}
|
|
@@ -1621,13 +1606,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1621
1606
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1622
1607
|
const signature = args.parseResponse(responseUr);
|
|
1623
1608
|
_KeystoneAdapter._assertRequestIdMatches(requestId, signature.requestId);
|
|
1624
|
-
return (0,
|
|
1609
|
+
return (0, import_hwk_adapter_core3.success)(args.toPayload(signature));
|
|
1625
1610
|
});
|
|
1626
1611
|
}
|
|
1627
1612
|
_allNetworkSyncSchema(item) {
|
|
1628
|
-
if (!(0,
|
|
1613
|
+
if (!(0, import_hwk_adapter_core3.isAllNetworkMethodName)(String(item.methodName)) || !item.path) return void 0;
|
|
1629
1614
|
const method = item.methodName;
|
|
1630
|
-
const hwkChain = (0,
|
|
1615
|
+
const hwkChain = (0, import_hwk_adapter_core3.getAllNetworkMethodChain)(method);
|
|
1631
1616
|
const path = normalizePath(item.path);
|
|
1632
1617
|
if (hwkChain === "btc" && !isKeystoneSignableBtcAccountPath(splitAccountPath(path).accountPath)) {
|
|
1633
1618
|
return void 0;
|
|
@@ -1665,30 +1650,26 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1665
1650
|
const assertAllBooked = () => {
|
|
1666
1651
|
for (const schema of requestedSchemas) {
|
|
1667
1652
|
if (!book.has(accountKey(schema.hwkChain, schema.path))) {
|
|
1668
|
-
throw (0,
|
|
1669
|
-
code:
|
|
1653
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1654
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
1670
1655
|
message: `Keystone did not return the requested derivation path (${schema.path})`
|
|
1671
1656
|
});
|
|
1672
1657
|
}
|
|
1673
1658
|
}
|
|
1674
1659
|
};
|
|
1675
|
-
const operation = (0,
|
|
1660
|
+
const operation = (0, import_hwk_adapter_core3.isHardwareOperationId)(params.operationId) ? this._operations.find(params.operationId) : void 0;
|
|
1676
1661
|
const operationRoute = operation ? this._operationRoutes.get(operation.connectId) : void 0;
|
|
1677
1662
|
const routedToQr = operationRoute?.operationId === operation?.operationId && operationRoute?.connectionType === "qr";
|
|
1678
|
-
if (this._forcedTransport !== "qr" && !routedToQr && !record?.usbSessionId && this._usbConnector && target.
|
|
1679
|
-
record = await this._tryUsbAttach(
|
|
1680
|
-
signal,
|
|
1681
|
-
target.expectedWalletId,
|
|
1682
|
-
record?.masterFingerprint ?? target.expectedMasterFingerprint
|
|
1683
|
-
) ?? record;
|
|
1663
|
+
if (this._forcedTransport !== "qr" && !routedToQr && !record?.usbSessionId && this._usbConnector && target.expectedMasterFingerprint) {
|
|
1664
|
+
record = await this._tryUsbAttach(signal, target.expectedMasterFingerprint) ?? record;
|
|
1684
1665
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1685
1666
|
}
|
|
1686
1667
|
if (this._forcedTransport !== "qr" && !routedToQr && record?.usbSessionId) {
|
|
1687
1668
|
const bundleSessionId = record.usbSessionId;
|
|
1688
1669
|
const assertBundleSession = () => {
|
|
1689
1670
|
if (record?.usbSessionId !== bundleSessionId) {
|
|
1690
|
-
throw (0,
|
|
1691
|
-
code:
|
|
1671
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1672
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.TransportNotAvailable,
|
|
1692
1673
|
message: "Keystone USB connection was lost during account export"
|
|
1693
1674
|
});
|
|
1694
1675
|
}
|
|
@@ -1709,20 +1690,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1709
1690
|
}
|
|
1710
1691
|
}
|
|
1711
1692
|
assertAllBooked();
|
|
1712
|
-
return { book,
|
|
1693
|
+
return { book, masterFingerprint: record.masterFingerprint };
|
|
1713
1694
|
}
|
|
1714
1695
|
if (this._forcedTransport === "usb") {
|
|
1715
|
-
throw (0,
|
|
1716
|
-
code:
|
|
1696
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1697
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.TransportNotAvailable,
|
|
1717
1698
|
message: "USB channel is not connected for this Keystone wallet"
|
|
1718
1699
|
});
|
|
1719
1700
|
}
|
|
1720
|
-
const schemas =
|
|
1721
|
-
{ hwkChain: "evm", path: KEYSTONE_WALLET_ID_PATH },
|
|
1722
|
-
...requestedSchemas.filter(
|
|
1723
|
-
(schema) => normalizePath(schema.path) !== KEYSTONE_WALLET_ID_PATH
|
|
1724
|
-
)
|
|
1725
|
-
];
|
|
1701
|
+
const schemas = requestedSchemas;
|
|
1726
1702
|
const requestUr = this.urEngine.buildKeyDerivationRequest({
|
|
1727
1703
|
schemas: schemas.map((schema) => keySchema(schema.hwkChain, schema.path)),
|
|
1728
1704
|
origin: this._origin
|
|
@@ -1747,78 +1723,54 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1747
1723
|
}
|
|
1748
1724
|
}
|
|
1749
1725
|
assertAllBooked();
|
|
1750
|
-
return { book,
|
|
1726
|
+
return { book, masterFingerprint: record.masterFingerprint };
|
|
1751
1727
|
});
|
|
1752
1728
|
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Resolve only the stable 64-hex wallet identity. The 8-hex BIP32 master
|
|
1755
|
-
* fingerprint is protocol metadata and is never accepted as a lookup key.
|
|
1756
|
-
*/
|
|
1729
|
+
/** Resolve the wallet's master fingerprint from the connectId and/or deviceId the caller passed. */
|
|
1757
1730
|
_resolveTarget(connectId, deviceId) {
|
|
1758
|
-
const resolvedConnectId = (0,
|
|
1731
|
+
const resolvedConnectId = (0, import_hwk_adapter_core3.isHardwareOperationId)(connectId) ? this._operations.resolve(connectId).connectId : connectId;
|
|
1759
1732
|
const identifiers = [deviceId, resolvedConnectId].filter(
|
|
1760
1733
|
(identifier) => Boolean(identifier)
|
|
1761
1734
|
);
|
|
1762
1735
|
if (!identifiers.length) return {};
|
|
1763
|
-
const
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1736
|
+
const fingerprints = identifiers.map((identifier) => keystoneMfpFromIdentifier(identifier));
|
|
1737
|
+
const expectedMasterFingerprint = fingerprints[0];
|
|
1738
|
+
if (!expectedMasterFingerprint || fingerprints.some((value) => !value)) {
|
|
1739
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1740
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceNotFound,
|
|
1741
|
+
message: "Keystone device lookup requires the wallet master fingerprint"
|
|
1768
1742
|
});
|
|
1769
1743
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1744
|
+
if (fingerprints.some((value) => value !== expectedMasterFingerprint)) {
|
|
1745
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1746
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
1774
1747
|
message: "Keystone connectId and deviceId identify different wallets"
|
|
1775
1748
|
});
|
|
1776
1749
|
}
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
});
|
|
1782
|
-
}
|
|
1783
|
-
const record = this._devices.get(expectedWalletId);
|
|
1784
|
-
return record ? {
|
|
1785
|
-
record,
|
|
1786
|
-
expectedWalletId,
|
|
1787
|
-
expectedMasterFingerprint: record.masterFingerprint
|
|
1788
|
-
} : { expectedWalletId };
|
|
1750
|
+
return {
|
|
1751
|
+
record: this._devices.get(expectedMasterFingerprint),
|
|
1752
|
+
expectedMasterFingerprint
|
|
1753
|
+
};
|
|
1789
1754
|
}
|
|
1790
1755
|
_assertParsedIdentity(parsed, expected) {
|
|
1791
|
-
const walletId = deriveKeystoneWalletId(parsed.accounts);
|
|
1792
1756
|
if (expected.expectedMasterFingerprint && parsed.masterFingerprint !== expected.expectedMasterFingerprint) {
|
|
1793
|
-
throw (0,
|
|
1794
|
-
code:
|
|
1757
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1758
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
1795
1759
|
message: `Connected Keystone wallet (mfp ${parsed.masterFingerprint}) does not match the requested wallet fingerprint (${expected.expectedMasterFingerprint})`
|
|
1796
1760
|
});
|
|
1797
1761
|
}
|
|
1798
|
-
if (expected.expectedWalletId && walletId !== expected.expectedWalletId) {
|
|
1799
|
-
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1800
|
-
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1801
|
-
message: "Connected Keystone wallet does not match the requested wallet identity"
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
return walletId;
|
|
1805
1762
|
}
|
|
1806
1763
|
/**
|
|
1807
1764
|
* Folds a parsed account response into the device table. Only non-USB round trips mark
|
|
1808
1765
|
* `qrSynced`, so a USB-only wallet is dropped on disconnect.
|
|
1809
1766
|
*/
|
|
1810
1767
|
_upsertDeviceRecord(parsed, options) {
|
|
1811
|
-
const
|
|
1812
|
-
let record = this._devices.get(
|
|
1768
|
+
const { masterFingerprint } = parsed;
|
|
1769
|
+
let record = this._devices.get(masterFingerprint);
|
|
1813
1770
|
const isNew = !record;
|
|
1814
1771
|
if (!record) {
|
|
1815
|
-
record = createDeviceRecord(
|
|
1816
|
-
this._devices.set(
|
|
1817
|
-
} else if (record.masterFingerprint !== parsed.masterFingerprint) {
|
|
1818
|
-
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1819
|
-
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1820
|
-
message: "Keystone wallet identity returned an inconsistent master fingerprint"
|
|
1821
|
-
});
|
|
1772
|
+
record = createDeviceRecord(masterFingerprint);
|
|
1773
|
+
this._devices.set(masterFingerprint, record);
|
|
1822
1774
|
}
|
|
1823
1775
|
record.model = parsed.device ?? record.model;
|
|
1824
1776
|
record.deviceVersion = parsed.deviceVersion ?? record.deviceVersion;
|
|
@@ -1826,18 +1778,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1826
1778
|
record.usbSessionId = options?.usbSessionId ?? record.usbSessionId;
|
|
1827
1779
|
if (!options?.viaUsb) record.qrSynced = true;
|
|
1828
1780
|
const info = toDeviceInfo(record);
|
|
1829
|
-
const eventType = isNew ?
|
|
1781
|
+
const eventType = isNew ? import_hwk_adapter_core3.DEVICE.CONNECT : import_hwk_adapter_core3.DEVICE.CHANGED;
|
|
1830
1782
|
this.emitter.emit(eventType, { type: eventType, payload: info });
|
|
1831
1783
|
return record;
|
|
1832
1784
|
}
|
|
1833
1785
|
/**
|
|
1834
|
-
* Opens a permitted USB Keystone
|
|
1835
|
-
*
|
|
1786
|
+
* Opens a permitted USB Keystone and takes its mfp as the wallet identity. A known wallet gains
|
|
1787
|
+
* USB in place (`device-changed`); an unseen one becomes USB-only.
|
|
1836
1788
|
*/
|
|
1837
1789
|
async _connectUsb(expected, searchTargetId, signal) {
|
|
1838
1790
|
if (this._pendingUsbTeardowns > 0 || this._abandonedUsbConnects > 0) {
|
|
1839
|
-
return (0,
|
|
1840
|
-
|
|
1791
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1792
|
+
import_hwk_adapter_core3.HardwareErrorCode.DeviceBusyInternal,
|
|
1841
1793
|
"Keystone USB session is being released"
|
|
1842
1794
|
);
|
|
1843
1795
|
}
|
|
@@ -1864,8 +1816,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1864
1816
|
}
|
|
1865
1817
|
async _connectUsbExclusive(expected, searchTargetId, signal) {
|
|
1866
1818
|
if (!this._usbConnector) {
|
|
1867
|
-
return (0,
|
|
1868
|
-
|
|
1819
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
1820
|
+
import_hwk_adapter_core3.HardwareErrorCode.TransportNotAvailable,
|
|
1869
1821
|
"No USB connector configured for this Keystone adapter"
|
|
1870
1822
|
);
|
|
1871
1823
|
}
|
|
@@ -1885,40 +1837,21 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1885
1837
|
sessionId = session.sessionId;
|
|
1886
1838
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1887
1839
|
const raw = session.deviceInfo.raw;
|
|
1888
|
-
const mfpValue = (0,
|
|
1840
|
+
const mfpValue = (0, import_hwk_adapter_core3.parseBip32MasterFingerprint)(raw?.masterFingerprint);
|
|
1889
1841
|
if (!mfpValue) {
|
|
1890
|
-
throw (0,
|
|
1891
|
-
code:
|
|
1842
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1843
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
1892
1844
|
message: "Keystone USB did not report a master fingerprint"
|
|
1893
1845
|
});
|
|
1894
1846
|
}
|
|
1895
1847
|
const masterFingerprint = mfpValue.toLowerCase();
|
|
1896
1848
|
if (expected.expectedMasterFingerprint && masterFingerprint !== expected.expectedMasterFingerprint) {
|
|
1897
|
-
throw (0,
|
|
1898
|
-
code:
|
|
1849
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1850
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
1899
1851
|
message: `Connected Keystone wallet (mfp ${masterFingerprint}) does not match the requested wallet fingerprint (${expected.expectedMasterFingerprint})`
|
|
1900
1852
|
});
|
|
1901
1853
|
}
|
|
1902
|
-
const
|
|
1903
|
-
schemas: [keySchema("evm", KEYSTONE_WALLET_ID_PATH)],
|
|
1904
|
-
origin: this._origin
|
|
1905
|
-
});
|
|
1906
|
-
const identityResult = await this._callUsbConnector(
|
|
1907
|
-
session.sessionId,
|
|
1908
|
-
"resolveUr",
|
|
1909
|
-
identityRequest
|
|
1910
|
-
);
|
|
1911
|
-
_KeystoneAdapter._throwIfAborted(signal);
|
|
1912
|
-
if (!identityResult.success) {
|
|
1913
|
-
throw (0, import_hwk_adapter_core4.rehydrateConnectorError)(identityResult.error);
|
|
1914
|
-
}
|
|
1915
|
-
const parsed = this.urEngine.parseAccountResponse(identityResult.payload);
|
|
1916
|
-
this._assertParsedIdentity(parsed, {
|
|
1917
|
-
...expected,
|
|
1918
|
-
expectedMasterFingerprint: expected.expectedMasterFingerprint ?? masterFingerprint
|
|
1919
|
-
});
|
|
1920
|
-
const walletId = deriveKeystoneWalletId(parsed.accounts);
|
|
1921
|
-
const previousUsbSessionId = this._devices.get(walletId)?.usbSessionId;
|
|
1854
|
+
const previousUsbSessionId = this._devices.get(masterFingerprint)?.usbSessionId;
|
|
1922
1855
|
if (previousUsbSessionId && previousUsbSessionId !== session.sessionId) {
|
|
1923
1856
|
try {
|
|
1924
1857
|
await this._usbConnector.disconnect(previousUsbSessionId);
|
|
@@ -1926,15 +1859,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1926
1859
|
}
|
|
1927
1860
|
}
|
|
1928
1861
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1929
|
-
const record = this._upsertDeviceRecord(
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1862
|
+
const record = this._upsertDeviceRecord(
|
|
1863
|
+
{ masterFingerprint, accounts: [] },
|
|
1864
|
+
{
|
|
1865
|
+
viaUsb: true,
|
|
1866
|
+
usbSessionId: session.sessionId
|
|
1867
|
+
}
|
|
1868
|
+
);
|
|
1933
1869
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1934
1870
|
record.hadUsbSession = true;
|
|
1935
1871
|
record.model = session.deviceInfo.modelName ?? session.deviceInfo.model ?? record.model;
|
|
1936
1872
|
record.deviceVersion = session.deviceInfo.firmwareVersion ?? record.deviceVersion;
|
|
1937
|
-
return (0,
|
|
1873
|
+
return (0, import_hwk_adapter_core3.success)(toDeviceInfo(record));
|
|
1938
1874
|
} catch (err) {
|
|
1939
1875
|
if (sessionId) {
|
|
1940
1876
|
try {
|
|
@@ -1949,9 +1885,9 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1949
1885
|
* Probes already-authorized USB devices without a permission picker, then attaches and verifies
|
|
1950
1886
|
* the requested wallet if present.
|
|
1951
1887
|
*/
|
|
1952
|
-
async _tryUsbAttach(signal,
|
|
1888
|
+
async _tryUsbAttach(signal, expectedMasterFingerprint, options) {
|
|
1953
1889
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1954
|
-
if (!
|
|
1890
|
+
if (!expectedMasterFingerprint || this._forcedTransport === "qr" || !this._usbConnector) {
|
|
1955
1891
|
return void 0;
|
|
1956
1892
|
}
|
|
1957
1893
|
const maxAttempts = options?.waitForReenumeration ? KEYSTONE_USB_REATTACH_PROBE_ATTEMPTS : 1;
|
|
@@ -1982,35 +1918,22 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1982
1918
|
}
|
|
1983
1919
|
return void 0;
|
|
1984
1920
|
}
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
signal
|
|
1993
|
-
);
|
|
1994
|
-
_KeystoneAdapter._throwIfAborted(signal);
|
|
1995
|
-
if (!attached.success && attached.payload.code === import_hwk_adapter_core4.HardwareErrorCode.DeviceBusyInternal) {
|
|
1996
|
-
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1997
|
-
...attached.payload,
|
|
1998
|
-
message: attached.payload.error
|
|
1999
|
-
});
|
|
2000
|
-
}
|
|
2001
|
-
if (attached.success) {
|
|
2002
|
-
record = this._devices.get(expectedWalletId);
|
|
2003
|
-
if (record) break;
|
|
2004
|
-
}
|
|
1921
|
+
const attached = await this._connectUsb({ expectedMasterFingerprint }, void 0, signal);
|
|
1922
|
+
_KeystoneAdapter._throwIfAborted(signal);
|
|
1923
|
+
if (!attached.success && attached.payload.code === import_hwk_adapter_core3.HardwareErrorCode.DeviceBusyInternal) {
|
|
1924
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1925
|
+
...attached.payload,
|
|
1926
|
+
message: attached.payload.error
|
|
1927
|
+
});
|
|
2005
1928
|
}
|
|
2006
|
-
return
|
|
1929
|
+
return attached.success ? this._devices.get(expectedMasterFingerprint) : void 0;
|
|
2007
1930
|
}
|
|
2008
1931
|
/**
|
|
2009
1932
|
* Decides QR vs USB for one UR round trip. A pinned 'usb' with no live session fails closed;
|
|
2010
1933
|
* otherwise a failed USB reattach leaves the call on QR.
|
|
2011
1934
|
*/
|
|
2012
1935
|
async _resolveUr(record, requestUr, animated, operationId, signal, operationName) {
|
|
2013
|
-
const releaseOperationRetention = (0,
|
|
1936
|
+
const releaseOperationRetention = (0, import_hwk_adapter_core3.isHardwareOperationId)(operationId) ? this._operations.retain(operationId) : void 0;
|
|
2014
1937
|
try {
|
|
2015
1938
|
return await this._resolveUrWithRoute(
|
|
2016
1939
|
record,
|
|
@@ -2024,9 +1947,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2024
1947
|
releaseOperationRetention?.();
|
|
2025
1948
|
}
|
|
2026
1949
|
}
|
|
2027
|
-
async _resolveUrWithRoute(
|
|
1950
|
+
async _resolveUrWithRoute(callerRecord, requestUr, animated, operationId, signal, operationName) {
|
|
1951
|
+
let record = callerRecord;
|
|
2028
1952
|
let interactionRoute;
|
|
2029
|
-
if ((0,
|
|
1953
|
+
if ((0, import_hwk_adapter_core3.isHardwareOperationId)(operationId)) {
|
|
2030
1954
|
const operation = this._operations.resolve(operationId);
|
|
2031
1955
|
const route = this._operationRoutes.get(operation.connectId);
|
|
2032
1956
|
if (!route || route.operationId !== operationId) {
|
|
@@ -2038,9 +1962,9 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2038
1962
|
interactionRoute = route;
|
|
2039
1963
|
}
|
|
2040
1964
|
if (!interactionRoute && !this._forcedTransport && record && !record.usbSessionId && this._usbConnector) {
|
|
2041
|
-
await this._tryUsbAttach(signal, record.
|
|
1965
|
+
record = await this._tryUsbAttach(signal, record.masterFingerprint, {
|
|
2042
1966
|
waitForReenumeration: record.hadUsbSession
|
|
2043
|
-
});
|
|
1967
|
+
}) ?? record;
|
|
2044
1968
|
}
|
|
2045
1969
|
const wantUsb = interactionRoute ? interactionRoute.connectionType === "usb" : this._forcedTransport === "usb" || this._forcedTransport !== "qr" && Boolean(record?.usbSessionId);
|
|
2046
1970
|
if (wantUsb) {
|
|
@@ -2051,8 +1975,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2051
1975
|
"Keystone operation USB connection was lost"
|
|
2052
1976
|
);
|
|
2053
1977
|
}
|
|
2054
|
-
throw (0,
|
|
2055
|
-
code:
|
|
1978
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
1979
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.TransportNotAvailable,
|
|
2056
1980
|
message: "USB channel is not connected for this Keystone wallet"
|
|
2057
1981
|
});
|
|
2058
1982
|
}
|
|
@@ -2063,9 +1987,9 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2063
1987
|
signal
|
|
2064
1988
|
);
|
|
2065
1989
|
if (result.success) return result.payload;
|
|
2066
|
-
const usbError = (0,
|
|
1990
|
+
const usbError = (0, import_hwk_adapter_core3.rehydrateConnectorError)(result.error);
|
|
2067
1991
|
const { origin: usbErrorOrigin, code: usbErrorCode } = usbError;
|
|
2068
|
-
if (usbErrorCode ===
|
|
1992
|
+
if (usbErrorCode === import_hwk_adapter_core3.HardwareErrorCode.PayloadTooLarge && usbErrorOrigin !== "device") {
|
|
2069
1993
|
if (!interactionRoute && !this._forcedTransport) {
|
|
2070
1994
|
const displayDevice2 = toDeviceInfo(record);
|
|
2071
1995
|
return this._requestQrDisplayAndAwaitResponse(
|
|
@@ -2076,7 +2000,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2076
2000
|
}
|
|
2077
2001
|
throw usbError;
|
|
2078
2002
|
}
|
|
2079
|
-
const deviceAnswered = usbErrorOrigin !== void 0 ? usbErrorOrigin === "device" : usbErrorCode ===
|
|
2003
|
+
const deviceAnswered = usbErrorOrigin !== void 0 ? usbErrorOrigin === "device" : usbErrorCode === import_hwk_adapter_core3.HardwareErrorCode.UserRejected || usbErrorCode === import_hwk_adapter_core3.HardwareErrorCode.UserAborted || usbErrorCode === import_hwk_adapter_core3.HardwareErrorCode.DeviceLocked || usbErrorCode === import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch;
|
|
2080
2004
|
if (!deviceAnswered) {
|
|
2081
2005
|
const lostSessionId = record.usbSessionId;
|
|
2082
2006
|
if (lostSessionId) {
|
|
@@ -2091,12 +2015,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2091
2015
|
);
|
|
2092
2016
|
}
|
|
2093
2017
|
if (operationName) {
|
|
2094
|
-
throw (0,
|
|
2095
|
-
code: usbErrorCode ??
|
|
2018
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2019
|
+
code: usbErrorCode ?? import_hwk_adapter_core3.HardwareErrorCode.TransportError,
|
|
2096
2020
|
message: `Keystone ${operationName} may have completed before the USB connection was lost`,
|
|
2097
2021
|
origin: "transport",
|
|
2098
2022
|
recovery: { scope: "unknown" },
|
|
2099
|
-
params: (0,
|
|
2023
|
+
params: (0, import_hwk_adapter_core3.operationMayHaveCompletedParams)(operationName)
|
|
2100
2024
|
});
|
|
2101
2025
|
}
|
|
2102
2026
|
}
|
|
@@ -2111,12 +2035,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2111
2035
|
);
|
|
2112
2036
|
} catch (error) {
|
|
2113
2037
|
const { code, _tag: tag } = error;
|
|
2114
|
-
if (operationName && (code ===
|
|
2115
|
-
throw (0,
|
|
2116
|
-
code:
|
|
2038
|
+
if (operationName && (code === import_hwk_adapter_core3.HardwareErrorCode.OperationTimeout || tag === import_hwk_adapter_core3.UI_REQUEST_TIMEOUT_TAG)) {
|
|
2039
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2040
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.OperationTimeout,
|
|
2117
2041
|
message: `Keystone ${operationName} may have completed before the QR response timed out`,
|
|
2118
2042
|
recovery: { scope: "unknown" },
|
|
2119
|
-
params: (0,
|
|
2043
|
+
params: (0, import_hwk_adapter_core3.operationMayHaveCompletedParams)(operationName)
|
|
2120
2044
|
});
|
|
2121
2045
|
}
|
|
2122
2046
|
throw error;
|
|
@@ -2126,11 +2050,11 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2126
2050
|
_endDisconnectedOperation(operationId, message, operationName) {
|
|
2127
2051
|
this._operations.end(operationId, "disconnect");
|
|
2128
2052
|
const params = { operationId, reason: "disconnect" };
|
|
2129
|
-
return (0,
|
|
2130
|
-
code:
|
|
2053
|
+
return (0, import_hwk_adapter_core3.createHwkError)({
|
|
2054
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.OperationEnded,
|
|
2131
2055
|
message,
|
|
2132
2056
|
recovery: operationName ? { scope: "unknown" } : void 0,
|
|
2133
|
-
params: operationName ? (0,
|
|
2057
|
+
params: operationName ? (0, import_hwk_adapter_core3.operationMayHaveCompletedParams)(operationName, params) : params
|
|
2134
2058
|
});
|
|
2135
2059
|
}
|
|
2136
2060
|
/**
|
|
@@ -2139,11 +2063,11 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2139
2063
|
*/
|
|
2140
2064
|
async _fetchAccount(connectId, deviceId, hwkChain, syncPath, signal, book) {
|
|
2141
2065
|
const target = this._resolveTarget(connectId, deviceId);
|
|
2142
|
-
const operationConnectionType = (0,
|
|
2066
|
+
const operationConnectionType = (0, import_hwk_adapter_core3.isHardwareOperationId)(connectId) ? this._operations.resolve(connectId).connectionType : void 0;
|
|
2143
2067
|
const key = accountKey(hwkChain, syncPath);
|
|
2144
2068
|
let existingRecord = target.record;
|
|
2145
2069
|
if (!existingRecord) {
|
|
2146
|
-
existingRecord = await this._tryUsbAttach(signal, target.
|
|
2070
|
+
existingRecord = await this._tryUsbAttach(signal, target.expectedMasterFingerprint);
|
|
2147
2071
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2148
2072
|
}
|
|
2149
2073
|
const booked = book?.get(key);
|
|
@@ -2151,14 +2075,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2151
2075
|
return { record: existingRecord, account: booked };
|
|
2152
2076
|
}
|
|
2153
2077
|
if (!operationConnectionType && existingRecord && !existingRecord.usbSessionId && this._forcedTransport === "usb") {
|
|
2154
|
-
await this._tryUsbAttach(signal, existingRecord.
|
|
2078
|
+
await this._tryUsbAttach(signal, existingRecord.masterFingerprint, {
|
|
2155
2079
|
waitForReenumeration: existingRecord.hadUsbSession
|
|
2156
2080
|
});
|
|
2157
2081
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2158
|
-
existingRecord = this._devices.get(existingRecord.
|
|
2082
|
+
existingRecord = this._devices.get(existingRecord.masterFingerprint) ?? existingRecord;
|
|
2159
2083
|
}
|
|
2160
2084
|
const useSinglePathUsbExport = operationConnectionType ? operationConnectionType === "usb" : this._forcedTransport !== "qr" && Boolean(existingRecord?.usbSessionId);
|
|
2161
|
-
const schemas =
|
|
2085
|
+
const schemas = [keySchema(hwkChain, syncPath)];
|
|
2162
2086
|
const requestUr = this.urEngine.buildKeyDerivationRequest({ schemas, origin: this._origin });
|
|
2163
2087
|
const responseUr = await this._resolveUr(existingRecord, requestUr, false, connectId, signal);
|
|
2164
2088
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
@@ -2166,8 +2090,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2166
2090
|
let record;
|
|
2167
2091
|
if (useSinglePathUsbExport && existingRecord) {
|
|
2168
2092
|
if (parsed.masterFingerprint !== existingRecord.masterFingerprint) {
|
|
2169
|
-
throw (0,
|
|
2170
|
-
code:
|
|
2093
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2094
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
2171
2095
|
message: "Keystone USB account export returned a different master fingerprint"
|
|
2172
2096
|
});
|
|
2173
2097
|
}
|
|
@@ -2180,8 +2104,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2180
2104
|
}
|
|
2181
2105
|
const account = parsed.accounts.find((a) => normalizePath(a.path) === syncPath);
|
|
2182
2106
|
if (!account) {
|
|
2183
|
-
throw (0,
|
|
2184
|
-
code:
|
|
2107
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2108
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
2185
2109
|
message: `Keystone did not return the requested derivation path (${syncPath})`
|
|
2186
2110
|
});
|
|
2187
2111
|
}
|
|
@@ -2207,17 +2131,20 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2207
2131
|
async _ensureWalletKnown(connectId, deviceId, chain, signal) {
|
|
2208
2132
|
const target = this._resolveTarget(connectId, deviceId);
|
|
2209
2133
|
if (target.record) return { record: target.record };
|
|
2210
|
-
const attached = await this._tryUsbAttach(signal, target.
|
|
2134
|
+
const attached = await this._tryUsbAttach(signal, target.expectedMasterFingerprint);
|
|
2211
2135
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2212
2136
|
if (attached) return { record: attached };
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2137
|
+
if (target.expectedMasterFingerprint) {
|
|
2138
|
+
return { record: createDeviceRecord(target.expectedMasterFingerprint) };
|
|
2139
|
+
}
|
|
2140
|
+
const { accountPath } = splitAccountPath(import_hwk_adapter_core3.CHAIN_FINGERPRINT_PATHS[chain]);
|
|
2141
|
+
const requestUr = this.urEngine.buildKeyDerivationRequest({
|
|
2142
|
+
schemas: [keySchema(chain, accountPath)],
|
|
2143
|
+
origin: this._origin
|
|
2144
|
+
});
|
|
2216
2145
|
const responseUr = await this._resolveUr(void 0, requestUr, false, connectId, signal);
|
|
2217
2146
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2218
|
-
|
|
2219
|
-
this._assertParsedIdentity(parsed, target);
|
|
2220
|
-
return { record: this._upsertDeviceRecord(parsed) };
|
|
2147
|
+
return { record: this._upsertDeviceRecord(this.urEngine.parseAccountResponse(responseUr)) };
|
|
2221
2148
|
}
|
|
2222
2149
|
/**
|
|
2223
2150
|
* The operation owning the running job, so a mid-call UI request can name it. Unpinned jobs map
|
|
@@ -2226,17 +2153,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2226
2153
|
_activeOperationId() {
|
|
2227
2154
|
const activeJobId = this._jobQueue.getActiveJob()?.deviceId;
|
|
2228
2155
|
if (!activeJobId) return void 0;
|
|
2229
|
-
if ((0,
|
|
2156
|
+
if ((0, import_hwk_adapter_core3.isHardwareOperationId)(activeJobId)) return activeJobId;
|
|
2230
2157
|
return this._operationRouteForIdentifier(activeJobId)?.operationId;
|
|
2231
2158
|
}
|
|
2232
|
-
/** Routes are keyed by connectId; a job key may be the bare
|
|
2159
|
+
/** Routes are keyed by connectId; a job key may be the bare master fingerprint. */
|
|
2233
2160
|
_operationRouteForIdentifier(identifier) {
|
|
2234
2161
|
for (const key of keystoneCancelQueueKeys([identifier])) {
|
|
2235
2162
|
const route = this._operationRoutes.get(key);
|
|
2236
2163
|
if (route) return route;
|
|
2237
2164
|
}
|
|
2238
|
-
const
|
|
2239
|
-
return
|
|
2165
|
+
const masterFingerprint = keystoneMfpFromIdentifier(identifier);
|
|
2166
|
+
return masterFingerprint ? this._operationRoutes.get(walletConnectId(masterFingerprint)) : void 0;
|
|
2240
2167
|
}
|
|
2241
2168
|
/**
|
|
2242
2169
|
* A QR prompt has no transport to interrupt; releasing the registry slot on abort is what lets
|
|
@@ -2260,15 +2187,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2260
2187
|
async _requestQrDisplayAndAwaitResponse(device, data, signal) {
|
|
2261
2188
|
const operationId = this._activeOperationId();
|
|
2262
2189
|
const waitPromise = this._uiRegistry.wait(
|
|
2263
|
-
|
|
2190
|
+
import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2264
2191
|
{ timeoutMs: this._qrTimeoutMs, operationId }
|
|
2265
2192
|
);
|
|
2266
|
-
this.emitter.emit(
|
|
2267
|
-
type:
|
|
2193
|
+
this.emitter.emit(import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_DISPLAY, {
|
|
2194
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2268
2195
|
payload: { device, data, operationId }
|
|
2269
2196
|
});
|
|
2270
2197
|
const response = await this._awaitQrResponse(
|
|
2271
|
-
|
|
2198
|
+
import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2272
2199
|
waitPromise,
|
|
2273
2200
|
signal
|
|
2274
2201
|
);
|
|
@@ -2277,32 +2204,32 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2277
2204
|
async _requestQrScanAndAwaitResponse(device, signal) {
|
|
2278
2205
|
const operationId = this._activeOperationId();
|
|
2279
2206
|
const waitPromise = this._uiRegistry.wait(
|
|
2280
|
-
|
|
2207
|
+
import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_SCAN,
|
|
2281
2208
|
{ timeoutMs: this._qrTimeoutMs, operationId }
|
|
2282
2209
|
);
|
|
2283
|
-
this.emitter.emit(
|
|
2284
|
-
type:
|
|
2210
|
+
this.emitter.emit(import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_SCAN, {
|
|
2211
|
+
type: import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_SCAN,
|
|
2285
2212
|
payload: { device, operationId }
|
|
2286
2213
|
});
|
|
2287
|
-
const response = await this._awaitQrResponse(
|
|
2214
|
+
const response = await this._awaitQrResponse(import_hwk_adapter_core3.UI_REQUEST.REQUEST_QR_SCAN, waitPromise, signal);
|
|
2288
2215
|
return { urType: response.urType, urData: response.urData };
|
|
2289
2216
|
}
|
|
2290
2217
|
async _callUsbConnector(sessionId, method, params, signal) {
|
|
2291
2218
|
if (!this._usbConnector) {
|
|
2292
|
-
throw (0,
|
|
2293
|
-
code:
|
|
2219
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2220
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.TransportNotAvailable,
|
|
2294
2221
|
message: "No USB connector configured for this Keystone adapter"
|
|
2295
2222
|
});
|
|
2296
2223
|
}
|
|
2297
2224
|
if (this._pendingUsbTeardowns > 0 || this._unsettledUsbOperations.size > 0) {
|
|
2298
|
-
throw (0,
|
|
2299
|
-
code:
|
|
2225
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2226
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceBusyInternal,
|
|
2300
2227
|
message: `Keystone USB is busy while calling ${method}`
|
|
2301
2228
|
});
|
|
2302
2229
|
}
|
|
2303
2230
|
if (signal?.aborted) {
|
|
2304
|
-
throw signal.reason instanceof Error ? signal.reason : (0,
|
|
2305
|
-
code:
|
|
2231
|
+
throw signal.reason instanceof Error ? signal.reason : (0, import_hwk_adapter_core3.createHwkError)({
|
|
2232
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.UserAborted,
|
|
2306
2233
|
message: "User aborted operation"
|
|
2307
2234
|
});
|
|
2308
2235
|
}
|
|
@@ -2383,16 +2310,16 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2383
2310
|
}
|
|
2384
2311
|
static _assertRequestIdMatches(expected, actual) {
|
|
2385
2312
|
if (actual && actual.toLowerCase() !== expected.toLowerCase()) {
|
|
2386
|
-
throw (0,
|
|
2387
|
-
code:
|
|
2313
|
+
throw (0, import_hwk_adapter_core3.createHwkError)({
|
|
2314
|
+
code: import_hwk_adapter_core3.HardwareErrorCode.DeviceMismatch,
|
|
2388
2315
|
message: "Keystone response requestId does not match the pending request \u2014 discarding a stale or unrelated scan"
|
|
2389
2316
|
});
|
|
2390
2317
|
}
|
|
2391
2318
|
}
|
|
2392
2319
|
_unsupported(method, reason) {
|
|
2393
2320
|
return Promise.resolve(
|
|
2394
|
-
(0,
|
|
2395
|
-
|
|
2321
|
+
(0, import_hwk_adapter_core3.failure)(
|
|
2322
|
+
import_hwk_adapter_core3.HardwareErrorCode.MethodNotSupported,
|
|
2396
2323
|
`KeystoneAdapter.${method} is not implemented yet: ${reason}`
|
|
2397
2324
|
)
|
|
2398
2325
|
);
|
|
@@ -2402,42 +2329,41 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2402
2329
|
const e = err;
|
|
2403
2330
|
if (typeof e.code === "number" && e.code >= 1e4 && e.code <= 99999) {
|
|
2404
2331
|
const { origin } = e;
|
|
2405
|
-
return (0,
|
|
2332
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
2406
2333
|
e.code,
|
|
2407
2334
|
e.message ?? "Unknown error",
|
|
2408
2335
|
e.params,
|
|
2409
2336
|
origin === "device" || origin === "transport" || origin === "host" ? origin : void 0,
|
|
2410
|
-
(0,
|
|
2337
|
+
(0, import_hwk_adapter_core3.isHwkRecoveryHint)(e.recovery) ? e.recovery : void 0
|
|
2411
2338
|
);
|
|
2412
2339
|
}
|
|
2413
|
-
if (e._tag ===
|
|
2414
|
-
return (0,
|
|
2415
|
-
|
|
2340
|
+
if (e._tag === import_hwk_adapter_core3.UI_REQUEST_CANCELLED_TAG || e._tag === import_hwk_adapter_core3.UI_REQUEST_PREEMPTED_TAG) {
|
|
2341
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
2342
|
+
import_hwk_adapter_core3.HardwareErrorCode.UserAborted,
|
|
2416
2343
|
e.message ?? "Keystone QR operation was cancelled"
|
|
2417
2344
|
);
|
|
2418
2345
|
}
|
|
2419
|
-
if (e._tag ===
|
|
2420
|
-
return (0,
|
|
2421
|
-
|
|
2346
|
+
if (e._tag === import_hwk_adapter_core3.UI_REQUEST_TIMEOUT_TAG) {
|
|
2347
|
+
return (0, import_hwk_adapter_core3.failure)(
|
|
2348
|
+
import_hwk_adapter_core3.HardwareErrorCode.OperationTimeout,
|
|
2422
2349
|
e.message ?? "Keystone QR operation timed out"
|
|
2423
2350
|
);
|
|
2424
2351
|
}
|
|
2425
2352
|
}
|
|
2426
2353
|
const message = err instanceof Error ? err.message : String(err);
|
|
2427
2354
|
const params = err instanceof Error && err.stack ? { stack: err.stack } : void 0;
|
|
2428
|
-
return (0,
|
|
2355
|
+
return (0, import_hwk_adapter_core3.failure)(import_hwk_adapter_core3.HardwareErrorCode.UnknownError, message, params);
|
|
2429
2356
|
}
|
|
2430
2357
|
};
|
|
2431
2358
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2432
2359
|
0 && (module.exports = {
|
|
2360
|
+
KEYSTONE_COLD_START_PATH,
|
|
2433
2361
|
KEYSTONE_WALLET_CONNECT_ID_PREFIX,
|
|
2434
|
-
KEYSTONE_WALLET_ID_PATH,
|
|
2435
2362
|
KeystoneAdapter,
|
|
2436
2363
|
KeystoneUrEngine,
|
|
2437
2364
|
accountKey,
|
|
2438
2365
|
btcScriptTypeFromPath,
|
|
2439
2366
|
createDeviceRecord,
|
|
2440
|
-
deriveKeystoneWalletId,
|
|
2441
2367
|
normalizePath,
|
|
2442
2368
|
placeholderDeviceInfo,
|
|
2443
2369
|
splitAccountPath,
|