@onekeyfe/hwk-keystone-adapter 1.2.3-alpha.3 → 1.2.3-alpha.8
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 +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +406 -277
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +207 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -67,6 +67,7 @@ var TronSignRequest = class _TronSignRequest extends import_bc_ur_registry.Regis
|
|
|
67
67
|
this.getSignData = () => this.signData;
|
|
68
68
|
this.getSignType = () => this.signType;
|
|
69
69
|
this.getDerivationPath = () => this.derivationPath.getPath();
|
|
70
|
+
this.getOrigin = () => this.origin;
|
|
70
71
|
this.toDataItem = () => {
|
|
71
72
|
const map = {};
|
|
72
73
|
if (this.requestId) {
|
|
@@ -473,7 +474,7 @@ var KeystoneUrEngine = class {
|
|
|
473
474
|
// src/adapter/KeystoneAdapter.ts
|
|
474
475
|
var import_bs58 = __toESM(require("bs58"));
|
|
475
476
|
var import_uuid2 = require("uuid");
|
|
476
|
-
var
|
|
477
|
+
var import_hwk_adapter_core4 = require("@onekeyfe/hwk-adapter-core");
|
|
477
478
|
|
|
478
479
|
// src/adapter/deviceTable.ts
|
|
479
480
|
var import_hwk_adapter_core2 = require("@onekeyfe/hwk-adapter-core");
|
|
@@ -584,12 +585,33 @@ function placeholderDeviceInfo() {
|
|
|
584
585
|
};
|
|
585
586
|
}
|
|
586
587
|
|
|
588
|
+
// src/utils/queueKey.ts
|
|
589
|
+
var import_hwk_adapter_core3 = require("@onekeyfe/hwk-adapter-core");
|
|
590
|
+
var KEYSTONE_COLD_START_JOB_LABEL = "keystone-cold-start";
|
|
591
|
+
function keystoneQueueKey(connectId, deviceId) {
|
|
592
|
+
return (0, import_hwk_adapter_core3.isHardwareOperationId)(connectId) ? connectId : deviceId || connectId || KEYSTONE_COLD_START_JOB_LABEL;
|
|
593
|
+
}
|
|
594
|
+
function keystoneWalletIdFromIdentifier(identifier) {
|
|
595
|
+
const value = identifier.startsWith(KEYSTONE_WALLET_CONNECT_ID_PREFIX) ? identifier.slice(KEYSTONE_WALLET_CONNECT_ID_PREFIX.length) : identifier;
|
|
596
|
+
return /^[0-9a-f]{64}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
597
|
+
}
|
|
598
|
+
function keystoneCancelQueueKeys(identifiers) {
|
|
599
|
+
const keys = /* @__PURE__ */ new Set();
|
|
600
|
+
for (const identifier of identifiers) {
|
|
601
|
+
if (identifier) {
|
|
602
|
+
keys.add(identifier);
|
|
603
|
+
const walletId = keystoneWalletIdFromIdentifier(identifier);
|
|
604
|
+
if (walletId) keys.add(walletId);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return keys;
|
|
608
|
+
}
|
|
609
|
+
|
|
587
610
|
// src/adapter/KeystoneAdapter.ts
|
|
588
|
-
var COLD_START_JOB_LABEL = "keystone-cold-start";
|
|
589
611
|
var KEYSTONE_USB_REATTACH_PROBE_ATTEMPTS = 4;
|
|
590
612
|
var KEYSTONE_USB_REATTACH_PROBE_INTERVAL_MS = 500;
|
|
591
613
|
function resolveHardwareOperationTarget(positionalTargetId, operationId) {
|
|
592
|
-
const result = (0,
|
|
614
|
+
const result = (0, import_hwk_adapter_core4.resolveHardwareOperationTarget)(positionalTargetId, operationId, "keystone");
|
|
593
615
|
return result;
|
|
594
616
|
}
|
|
595
617
|
function waitForKeystoneUsbReattachProbe() {
|
|
@@ -597,8 +619,11 @@ function waitForKeystoneUsbReattachProbe() {
|
|
|
597
619
|
setTimeout(resolve, KEYSTONE_USB_REATTACH_PROBE_INTERVAL_MS);
|
|
598
620
|
});
|
|
599
621
|
}
|
|
600
|
-
function
|
|
601
|
-
|
|
622
|
+
function buildCancelledFailure(signal) {
|
|
623
|
+
const reason = signal.reason;
|
|
624
|
+
const code = typeof reason?.code === "number" ? reason.code : import_hwk_adapter_core4.HardwareErrorCode.UserAborted;
|
|
625
|
+
const message = typeof reason?.message === "string" ? reason.message : "";
|
|
626
|
+
return (0, import_hwk_adapter_core4.failure)(code, message || "All-network get-address cancelled");
|
|
602
627
|
}
|
|
603
628
|
var BIP44_COIN_TYPE_TO_CHAIN = {
|
|
604
629
|
60: "evm",
|
|
@@ -613,17 +638,20 @@ function inferHwkChainFromPath(path) {
|
|
|
613
638
|
var KeystoneAdapter = class _KeystoneAdapter {
|
|
614
639
|
constructor(options) {
|
|
615
640
|
this.vendor = "keystone";
|
|
616
|
-
|
|
641
|
+
// No protocol-level cancel exists over Keystone USB, and QR has no transport
|
|
642
|
+
// to interrupt at all. Cancelling ends the wait, not the device's prompt.
|
|
643
|
+
this.cancelCapability = "stops-waiting";
|
|
644
|
+
this.emitter = new import_hwk_adapter_core4.TypedEventEmitter();
|
|
617
645
|
this._operationRoutes = /* @__PURE__ */ new Map();
|
|
618
|
-
this._operations = new
|
|
646
|
+
this._operations = new import_hwk_adapter_core4.OperationRegistry({
|
|
619
647
|
vendor: "keystone",
|
|
620
648
|
onEnded: (operation, reason) => {
|
|
621
649
|
const route = this._operationRoutes.get(operation.connectId);
|
|
622
650
|
if (route?.operationId === operation.operationId) {
|
|
623
651
|
this._operationRoutes.delete(operation.connectId);
|
|
624
652
|
}
|
|
625
|
-
this.emitter.emit(
|
|
626
|
-
type:
|
|
653
|
+
this.emitter.emit(import_hwk_adapter_core4.SDK.OPERATION_ENDED, {
|
|
654
|
+
type: import_hwk_adapter_core4.SDK.OPERATION_ENDED,
|
|
627
655
|
payload: { operationId: operation.operationId, reason }
|
|
628
656
|
});
|
|
629
657
|
if (reason === "timeout") {
|
|
@@ -631,7 +659,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
631
659
|
}
|
|
632
660
|
}
|
|
633
661
|
});
|
|
634
|
-
this._uiRegistry = new
|
|
662
|
+
this._uiRegistry = new import_hwk_adapter_core4.UiRequestRegistry();
|
|
635
663
|
this._devices = /* @__PURE__ */ new Map();
|
|
636
664
|
this._searchDeviceTargets = /* @__PURE__ */ new Map();
|
|
637
665
|
/** Serializes USB open/identity handshakes that run outside the job queue. */
|
|
@@ -648,10 +676,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
648
676
|
record.usbSessionId = void 0;
|
|
649
677
|
const info = toDeviceInfo(record);
|
|
650
678
|
if (record.qrSynced) {
|
|
651
|
-
this.emitter.emit(
|
|
679
|
+
this.emitter.emit(import_hwk_adapter_core4.DEVICE.CHANGED, { type: import_hwk_adapter_core4.DEVICE.CHANGED, payload: info });
|
|
652
680
|
} else {
|
|
653
681
|
this._devices.delete(record.walletId);
|
|
654
|
-
this.emitter.emit(
|
|
682
|
+
this.emitter.emit(import_hwk_adapter_core4.DEVICE.DISCONNECT, { type: import_hwk_adapter_core4.DEVICE.DISCONNECT, payload: info });
|
|
655
683
|
}
|
|
656
684
|
};
|
|
657
685
|
this._handleUsbUiEvent = (event) => {
|
|
@@ -666,6 +694,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
666
694
|
if (!operationTarget.success) return operationTarget;
|
|
667
695
|
const effectiveConnectId = operationTarget.payload.targetId ?? "";
|
|
668
696
|
const { operationId } = operationTarget.payload;
|
|
697
|
+
let cancelScope;
|
|
669
698
|
try {
|
|
670
699
|
const prefetched = await this._prefetchAllNetworkAccounts(
|
|
671
700
|
effectiveConnectId,
|
|
@@ -674,11 +703,20 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
674
703
|
);
|
|
675
704
|
const { book } = prefetched;
|
|
676
705
|
const itemDeviceId = deviceId || prefetched.walletId || "";
|
|
677
|
-
|
|
706
|
+
const scope = this._jobQueue.createCancelScope(
|
|
707
|
+
keystoneQueueKey(effectiveConnectId, itemDeviceId)
|
|
708
|
+
);
|
|
709
|
+
cancelScope = scope;
|
|
710
|
+
const cancelledIndexes = /* @__PURE__ */ new Set();
|
|
711
|
+
return await (0, import_hwk_adapter_core4.runAllNetworkGetAddress)({
|
|
678
712
|
connectId: effectiveConnectId,
|
|
679
713
|
deviceId: itemDeviceId,
|
|
680
714
|
params,
|
|
681
|
-
callItem: async ({ method, item }) => {
|
|
715
|
+
callItem: async ({ method, item, index }) => {
|
|
716
|
+
if (scope.signal.aborted) {
|
|
717
|
+
cancelledIndexes.add(index);
|
|
718
|
+
return buildCancelledFailure(scope.signal);
|
|
719
|
+
}
|
|
682
720
|
const commonArgs = {
|
|
683
721
|
path: item.path,
|
|
684
722
|
showOnDevice: item.showOnDevice,
|
|
@@ -696,8 +734,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
696
734
|
case "tronGetAddress":
|
|
697
735
|
return this.tronGetAddress(effectiveConnectId, itemDeviceId, commonArgs, book);
|
|
698
736
|
default:
|
|
699
|
-
return (0,
|
|
700
|
-
|
|
737
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
738
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
701
739
|
`Unsupported method: ${String(method)}`
|
|
702
740
|
);
|
|
703
741
|
}
|
|
@@ -717,16 +755,25 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
717
755
|
} : void 0
|
|
718
756
|
}
|
|
719
757
|
});
|
|
758
|
+
},
|
|
759
|
+
// The gap check plus the shared top-level table: a refusal or a lost
|
|
760
|
+
// session ends the batch, every other per-item failure keeps its
|
|
761
|
+
// existing "carry on with the next chain" behaviour.
|
|
762
|
+
shouldAbortBundle: (response, { index }) => {
|
|
763
|
+
const { code } = response.payload ?? {};
|
|
764
|
+
return cancelledIndexes.has(index) || (0, import_hwk_adapter_core4.isUserRefusal)(code) || (0, import_hwk_adapter_core4.isConnectionLost)(code);
|
|
720
765
|
}
|
|
721
766
|
});
|
|
722
767
|
} catch (err) {
|
|
723
768
|
return this._errorToFailure(err);
|
|
769
|
+
} finally {
|
|
770
|
+
cancelScope?.release();
|
|
724
771
|
}
|
|
725
772
|
};
|
|
726
773
|
this._origin = options?.origin ?? "OneKey";
|
|
727
774
|
this._qrTimeoutMs = options?.qrTimeoutMs;
|
|
728
775
|
this.urEngine = new KeystoneUrEngine(this._origin);
|
|
729
|
-
this._jobQueue = new
|
|
776
|
+
this._jobQueue = new import_hwk_adapter_core4.DeviceJobQueue();
|
|
730
777
|
this._usbConnector = options?.usbConnector;
|
|
731
778
|
this._usbConnector?.on("device-disconnect", this._handleUsbDisconnect);
|
|
732
779
|
this._usbConnector?.on("ui-event", this._handleUsbUiEvent);
|
|
@@ -786,7 +833,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
786
833
|
}
|
|
787
834
|
const known = Array.from(this._devices.values()).map(toDeviceInfo);
|
|
788
835
|
if (options?.transportType === "qr") {
|
|
789
|
-
const searchTargetId = (0,
|
|
836
|
+
const searchTargetId = (0, import_hwk_adapter_core4.createHardwareSearchTargetId)("keystone");
|
|
790
837
|
this._searchDeviceTargets.set(searchTargetId, "qr");
|
|
791
838
|
return [
|
|
792
839
|
{
|
|
@@ -882,15 +929,15 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
882
929
|
} else if (discoveredConnectionType === "usb") {
|
|
883
930
|
selectedConnectionType = "usb";
|
|
884
931
|
if (!this._usbConnector) {
|
|
885
|
-
return (0,
|
|
886
|
-
|
|
932
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
933
|
+
import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
887
934
|
"No USB connector configured for this Keystone adapter"
|
|
888
935
|
);
|
|
889
936
|
}
|
|
890
937
|
connected = await this._connectUsb({}, searchTargetId);
|
|
891
|
-
} else if ((0,
|
|
892
|
-
return (0,
|
|
893
|
-
|
|
938
|
+
} else if ((0, import_hwk_adapter_core4.hasHardwareRuntimeIdPrefix)(searchTargetId)) {
|
|
939
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
940
|
+
import_hwk_adapter_core4.HardwareErrorCode.DeviceNotFound,
|
|
894
941
|
"Keystone search target has expired; search for devices again",
|
|
895
942
|
void 0,
|
|
896
943
|
void 0,
|
|
@@ -900,10 +947,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
900
947
|
const target = this._resolveTarget(searchTargetId);
|
|
901
948
|
if (target.record) {
|
|
902
949
|
selectedConnectionType = target.record.usbSessionId ? "usb" : "qr";
|
|
903
|
-
connected = (0,
|
|
950
|
+
connected = (0, import_hwk_adapter_core4.success)(toDeviceInfo(target.record));
|
|
904
951
|
} else if (!this._usbConnector) {
|
|
905
|
-
return (0,
|
|
906
|
-
|
|
952
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
953
|
+
import_hwk_adapter_core4.HardwareErrorCode.DeviceNotFound,
|
|
907
954
|
`Unknown Keystone device search target: ${searchTargetId}`
|
|
908
955
|
);
|
|
909
956
|
} else {
|
|
@@ -918,13 +965,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
918
965
|
searchTargetId,
|
|
919
966
|
connectId: connected.payload.connectId,
|
|
920
967
|
device: connected.payload,
|
|
968
|
+
connectionType: selectedConnectionType,
|
|
921
969
|
connectionKeys: selectedConnectionType === "usb" && record?.usbSessionId ? [record.usbSessionId] : []
|
|
922
970
|
});
|
|
923
971
|
this._operationRoutes.set(connected.payload.connectId, {
|
|
924
972
|
operationId: operation.operationId,
|
|
925
973
|
connectionType: selectedConnectionType
|
|
926
974
|
});
|
|
927
|
-
return (0,
|
|
975
|
+
return (0, import_hwk_adapter_core4.success)(operation.operationId);
|
|
928
976
|
} catch (err) {
|
|
929
977
|
return this._errorToFailure(err);
|
|
930
978
|
}
|
|
@@ -970,41 +1018,51 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
970
1018
|
}
|
|
971
1019
|
getDeviceInfo(connectIdOrOperationId, deviceId) {
|
|
972
1020
|
try {
|
|
973
|
-
const connectId = (0,
|
|
1021
|
+
const connectId = (0, import_hwk_adapter_core4.isHardwareOperationId)(connectIdOrOperationId) ? this._operations.resolve(connectIdOrOperationId).connectId : connectIdOrOperationId;
|
|
974
1022
|
const { record } = this._resolveTarget(connectId, deviceId);
|
|
975
1023
|
if (!record) {
|
|
976
1024
|
return Promise.resolve(
|
|
977
|
-
(0,
|
|
978
|
-
|
|
1025
|
+
(0, import_hwk_adapter_core4.failure)(
|
|
1026
|
+
import_hwk_adapter_core4.HardwareErrorCode.DeviceNotFound,
|
|
979
1027
|
`Unknown Keystone device: ${connectId || deviceId}`
|
|
980
1028
|
)
|
|
981
1029
|
);
|
|
982
1030
|
}
|
|
983
|
-
return Promise.resolve((0,
|
|
1031
|
+
return Promise.resolve((0, import_hwk_adapter_core4.success)(toDeviceInfo(record)));
|
|
984
1032
|
} catch (err) {
|
|
985
1033
|
return Promise.resolve(this._errorToFailure(err));
|
|
986
1034
|
}
|
|
987
1035
|
}
|
|
988
1036
|
cancel(connectId) {
|
|
989
|
-
|
|
990
|
-
|
|
1037
|
+
let namedOperationConnectId;
|
|
1038
|
+
if ((0, import_hwk_adapter_core4.isHardwareOperationId)(connectId)) {
|
|
1039
|
+
try {
|
|
1040
|
+
namedOperationConnectId = this._operations.resolve(connectId).connectId;
|
|
1041
|
+
} catch {
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
const reason = (0, import_hwk_adapter_core4.createHwkError)({
|
|
1046
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.UserAborted,
|
|
991
1047
|
message: "User aborted operation"
|
|
992
1048
|
});
|
|
993
|
-
const activeJobId = this._jobQueue.getActiveJob()?.deviceId;
|
|
994
1049
|
if (connectId) {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1050
|
+
const queueKeys = keystoneCancelQueueKeys([
|
|
1051
|
+
connectId,
|
|
1052
|
+
this._operationRoutes.get(connectId)?.operationId,
|
|
1053
|
+
namedOperationConnectId
|
|
1054
|
+
]);
|
|
1055
|
+
for (const key of queueKeys) {
|
|
1056
|
+
this._jobQueue.cancelActiveAndPending(key, reason);
|
|
1057
|
+
}
|
|
1058
|
+
const scopedOperationId = (0, import_hwk_adapter_core4.isHardwareOperationId)(connectId) ? connectId : this._operationRouteForIdentifier(connectId)?.operationId;
|
|
1059
|
+
if (scopedOperationId) {
|
|
1060
|
+
this._uiRegistry.cancel(void 0, void 0, scopedOperationId);
|
|
1002
1061
|
}
|
|
1003
|
-
this._jobQueue.cancelActiveAndPending(activeJobId, reason);
|
|
1004
1062
|
} else {
|
|
1005
1063
|
this._jobQueue.cancelActiveAndPending(void 0, reason);
|
|
1064
|
+
this._uiRegistry.cancel();
|
|
1006
1065
|
}
|
|
1007
|
-
this._uiRegistry.cancel();
|
|
1008
1066
|
}
|
|
1009
1067
|
getChainFingerprint(connectId, deviceId, chain) {
|
|
1010
1068
|
try {
|
|
@@ -1012,16 +1070,16 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1012
1070
|
const walletId = target.record?.walletId ?? target.expectedWalletId;
|
|
1013
1071
|
if (!walletId) {
|
|
1014
1072
|
return Promise.resolve(
|
|
1015
|
-
(0,
|
|
1073
|
+
(0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DeviceNotFound, "Unknown Keystone wallet identity")
|
|
1016
1074
|
);
|
|
1017
1075
|
}
|
|
1018
|
-
return Promise.resolve((0,
|
|
1076
|
+
return Promise.resolve((0, import_hwk_adapter_core4.success)((0, import_hwk_adapter_core4.deriveDeviceFingerprint)(`keystone:${chain}:${walletId}`)));
|
|
1019
1077
|
} catch (err) {
|
|
1020
1078
|
return Promise.resolve(this._errorToFailure(err));
|
|
1021
1079
|
}
|
|
1022
1080
|
}
|
|
1023
1081
|
uiResponse(response) {
|
|
1024
|
-
if (response.type ===
|
|
1082
|
+
if (response.type === import_hwk_adapter_core4.UI_RESPONSE.CANCEL) {
|
|
1025
1083
|
this.cancel();
|
|
1026
1084
|
return;
|
|
1027
1085
|
}
|
|
@@ -1039,25 +1097,26 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1039
1097
|
// ---------------------------------------------------------------------------
|
|
1040
1098
|
async importFromQr(options = {}) {
|
|
1041
1099
|
try {
|
|
1042
|
-
return await this._jobQueue.enqueue(
|
|
1100
|
+
return await this._jobQueue.enqueue(KEYSTONE_COLD_START_JOB_LABEL, async (signal) => {
|
|
1043
1101
|
const displayDevice = placeholderDeviceInfo();
|
|
1044
1102
|
let responseUr;
|
|
1045
1103
|
if (options.mode === "scan") {
|
|
1046
|
-
responseUr = await this._requestQrScanAndAwaitResponse(displayDevice);
|
|
1104
|
+
responseUr = await this._requestQrScanAndAwaitResponse(displayDevice, signal);
|
|
1047
1105
|
} else {
|
|
1048
1106
|
const requestUr = this.urEngine.buildKeyDerivationRequest({
|
|
1049
1107
|
schemas: [{ path: KEYSTONE_WALLET_ID_PATH, curve: "secp256k1" }],
|
|
1050
1108
|
origin: this._origin
|
|
1051
1109
|
});
|
|
1052
|
-
responseUr = await this._requestQrDisplayAndAwaitResponse(
|
|
1053
|
-
|
|
1054
|
-
animated: false
|
|
1055
|
-
|
|
1110
|
+
responseUr = await this._requestQrDisplayAndAwaitResponse(
|
|
1111
|
+
displayDevice,
|
|
1112
|
+
{ ...requestUr, animated: false },
|
|
1113
|
+
signal
|
|
1114
|
+
);
|
|
1056
1115
|
}
|
|
1057
1116
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1058
1117
|
const parsed = this.urEngine.parseAccountResponse(responseUr);
|
|
1059
1118
|
const record = this._upsertDeviceRecord(parsed);
|
|
1060
|
-
return (0,
|
|
1119
|
+
return (0, import_hwk_adapter_core4.success)(toDeviceInfo(record));
|
|
1061
1120
|
});
|
|
1062
1121
|
} catch (err) {
|
|
1063
1122
|
return this._errorToFailure(err);
|
|
@@ -1072,18 +1131,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1072
1131
|
const connectId = operationTarget.payload.targetId;
|
|
1073
1132
|
const deviceId = deviceIdArg ?? void 0;
|
|
1074
1133
|
const params = paramsArg;
|
|
1075
|
-
if (!params) return (0,
|
|
1134
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmGetAddress requires params");
|
|
1076
1135
|
if (!params.path)
|
|
1077
|
-
return (0,
|
|
1136
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmGetAddress requires params.path");
|
|
1078
1137
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1079
1138
|
if (!relativeDerivePath) {
|
|
1080
|
-
return (0,
|
|
1081
|
-
|
|
1139
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1140
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1082
1141
|
"evmGetAddress requires a full leaf path, e.g. m/44'/60'/0'/0/0"
|
|
1083
1142
|
);
|
|
1084
1143
|
}
|
|
1085
1144
|
try {
|
|
1086
|
-
return await this._jobQueue.enqueue(
|
|
1145
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1087
1146
|
const { account } = await this._fetchAccount(
|
|
1088
1147
|
connectId,
|
|
1089
1148
|
deviceId,
|
|
@@ -1094,8 +1153,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1094
1153
|
);
|
|
1095
1154
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1096
1155
|
if (!account.extendedPublicKey) {
|
|
1097
|
-
throw (0,
|
|
1098
|
-
code:
|
|
1156
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1157
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1099
1158
|
message: "Keystone did not return an extended public key for this account path"
|
|
1100
1159
|
});
|
|
1101
1160
|
}
|
|
@@ -1103,7 +1162,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1103
1162
|
account.extendedPublicKey,
|
|
1104
1163
|
relativeDerivePath
|
|
1105
1164
|
);
|
|
1106
|
-
return (0,
|
|
1165
|
+
return (0, import_hwk_adapter_core4.success)({ address, path: normalizePath(params.path) });
|
|
1107
1166
|
});
|
|
1108
1167
|
} catch (err) {
|
|
1109
1168
|
return this._errorToFailure(err);
|
|
@@ -1116,20 +1175,20 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1116
1175
|
const deviceId = deviceIdArg ?? void 0;
|
|
1117
1176
|
const params = paramsArg;
|
|
1118
1177
|
if (!params)
|
|
1119
|
-
return (0,
|
|
1178
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmSignTransaction requires params");
|
|
1120
1179
|
if (!params.path) {
|
|
1121
|
-
return (0,
|
|
1180
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmSignTransaction requires params.path");
|
|
1122
1181
|
}
|
|
1123
1182
|
if (!("serializedTx" in params) || typeof params.serializedTx !== "string" || !params.serializedTx) {
|
|
1124
|
-
return (0,
|
|
1125
|
-
|
|
1183
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1184
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1126
1185
|
"Keystone only signs a fully RLP-serialized transaction (params.serializedTx) \u2014 structured-field signing is not supported"
|
|
1127
1186
|
);
|
|
1128
1187
|
}
|
|
1129
|
-
const rawTxHex = (0,
|
|
1188
|
+
const rawTxHex = (0, import_hwk_adapter_core4.stripHex)(params.serializedTx);
|
|
1130
1189
|
const path = normalizePath(params.path);
|
|
1131
1190
|
try {
|
|
1132
|
-
return await this._jobQueue.enqueue(
|
|
1191
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1133
1192
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "evm", signal);
|
|
1134
1193
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1135
1194
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1140,7 +1199,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1140
1199
|
dataType,
|
|
1141
1200
|
path,
|
|
1142
1201
|
xfp: record.masterFingerprint,
|
|
1143
|
-
chainId: params.chainId
|
|
1202
|
+
chainId: params.chainId,
|
|
1203
|
+
origin: this._origin
|
|
1144
1204
|
});
|
|
1145
1205
|
const responseUr = await this._resolveUr(
|
|
1146
1206
|
record,
|
|
@@ -1153,10 +1213,10 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1153
1213
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1154
1214
|
const sig = this.urEngine.parseEthSignature(responseUr);
|
|
1155
1215
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1156
|
-
return (0,
|
|
1157
|
-
v: (0,
|
|
1158
|
-
r: (0,
|
|
1159
|
-
s: (0,
|
|
1216
|
+
return (0, import_hwk_adapter_core4.success)({
|
|
1217
|
+
v: (0, import_hwk_adapter_core4.ensure0x)(sig.v),
|
|
1218
|
+
r: (0, import_hwk_adapter_core4.ensure0x)(sig.r),
|
|
1219
|
+
s: (0, import_hwk_adapter_core4.ensure0x)(sig.s)
|
|
1160
1220
|
});
|
|
1161
1221
|
});
|
|
1162
1222
|
} catch (err) {
|
|
@@ -1169,17 +1229,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1169
1229
|
const connectId = operationTarget.payload.targetId;
|
|
1170
1230
|
const deviceId = deviceIdArg ?? void 0;
|
|
1171
1231
|
const params = paramsArg;
|
|
1172
|
-
if (!params) return (0,
|
|
1232
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmSignMessage requires params");
|
|
1173
1233
|
if (!params.path || params.message === void 0) {
|
|
1174
|
-
return (0,
|
|
1175
|
-
|
|
1234
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1235
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1176
1236
|
"evmSignMessage requires params.path and params.message"
|
|
1177
1237
|
);
|
|
1178
1238
|
}
|
|
1179
|
-
const messageHex = params.hex ? (0,
|
|
1239
|
+
const messageHex = params.hex ? (0, import_hwk_adapter_core4.stripHex)(params.message) : Buffer.from(params.message, "utf8").toString("hex");
|
|
1180
1240
|
const path = normalizePath(params.path);
|
|
1181
1241
|
try {
|
|
1182
|
-
return await this._jobQueue.enqueue(
|
|
1242
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1183
1243
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "evm", signal);
|
|
1184
1244
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1185
1245
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1189,7 +1249,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1189
1249
|
dataType: "personalMessage",
|
|
1190
1250
|
path,
|
|
1191
1251
|
xfp: record.masterFingerprint,
|
|
1192
|
-
chainId: params.chainId
|
|
1252
|
+
chainId: params.chainId,
|
|
1253
|
+
origin: this._origin
|
|
1193
1254
|
});
|
|
1194
1255
|
const responseUr = await this._resolveUr(
|
|
1195
1256
|
record,
|
|
@@ -1202,7 +1263,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1202
1263
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1203
1264
|
const sig = this.urEngine.parseEthSignature(responseUr);
|
|
1204
1265
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1205
|
-
return (0,
|
|
1266
|
+
return (0, import_hwk_adapter_core4.success)({ signature: (0, import_hwk_adapter_core4.ensure0x)(sig.r + sig.s + sig.v) });
|
|
1206
1267
|
});
|
|
1207
1268
|
} catch (err) {
|
|
1208
1269
|
return this._errorToFailure(err);
|
|
@@ -1215,13 +1276,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1215
1276
|
const deviceId = deviceIdArg ?? void 0;
|
|
1216
1277
|
const params = paramsArg;
|
|
1217
1278
|
if (!params)
|
|
1218
|
-
return (0,
|
|
1279
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmSignTypedData requires params");
|
|
1219
1280
|
if (!params.path) {
|
|
1220
|
-
return (0,
|
|
1281
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "evmSignTypedData requires params.path");
|
|
1221
1282
|
}
|
|
1222
1283
|
if (params.mode === "hash") {
|
|
1223
|
-
return (0,
|
|
1224
|
-
|
|
1284
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1285
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1225
1286
|
"Keystone always displays the full EIP-712 payload for on-device review \u2014 pre-hashed signing is not supported"
|
|
1226
1287
|
);
|
|
1227
1288
|
}
|
|
@@ -1231,7 +1292,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1231
1292
|
).toString("hex");
|
|
1232
1293
|
const path = normalizePath(params.path);
|
|
1233
1294
|
try {
|
|
1234
|
-
return await this._jobQueue.enqueue(
|
|
1295
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1235
1296
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "evm", signal);
|
|
1236
1297
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1237
1298
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1241,7 +1302,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1241
1302
|
dataType: "typedData",
|
|
1242
1303
|
path,
|
|
1243
1304
|
xfp: record.masterFingerprint,
|
|
1244
|
-
chainId: params.chainId
|
|
1305
|
+
chainId: params.chainId,
|
|
1306
|
+
origin: this._origin
|
|
1245
1307
|
});
|
|
1246
1308
|
const responseUr = await this._resolveUr(
|
|
1247
1309
|
record,
|
|
@@ -1254,7 +1316,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1254
1316
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1255
1317
|
const sig = this.urEngine.parseEthSignature(responseUr);
|
|
1256
1318
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1257
|
-
return (0,
|
|
1319
|
+
return (0, import_hwk_adapter_core4.success)({ signature: (0, import_hwk_adapter_core4.ensure0x)(sig.r + sig.s + sig.v) });
|
|
1258
1320
|
});
|
|
1259
1321
|
} catch (err) {
|
|
1260
1322
|
return this._errorToFailure(err);
|
|
@@ -1272,13 +1334,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1272
1334
|
const connectId = operationTarget.payload.targetId;
|
|
1273
1335
|
const deviceId = deviceIdArg ?? void 0;
|
|
1274
1336
|
const params = paramsArg;
|
|
1275
|
-
if (!params) return (0,
|
|
1337
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcGetAddress requires params");
|
|
1276
1338
|
if (!params.path)
|
|
1277
|
-
return (0,
|
|
1339
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcGetAddress requires params.path");
|
|
1278
1340
|
const scriptType = btcScriptTypeFromPath(params.path);
|
|
1279
1341
|
if (!scriptType) {
|
|
1280
|
-
return (0,
|
|
1281
|
-
|
|
1342
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1343
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1282
1344
|
"btcGetAddress requires a path whose purpose is 44'/49'/84'/86' (P2PKH/P2SH-P2WPKH/P2WPKH/P2TR)"
|
|
1283
1345
|
);
|
|
1284
1346
|
}
|
|
@@ -1291,16 +1353,16 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1291
1353
|
const normalizedPath = normalizePath(params.path);
|
|
1292
1354
|
const { accountPath, relativeDerivePath } = splitAccountPath(normalizedPath);
|
|
1293
1355
|
if (!relativeDerivePath) {
|
|
1294
|
-
return (0,
|
|
1295
|
-
|
|
1356
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1357
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1296
1358
|
"btcGetAddress requires a full leaf path, e.g. m/84'/0'/0'/0/0"
|
|
1297
1359
|
);
|
|
1298
1360
|
}
|
|
1299
1361
|
if (!isKeystoneSignableBtcAccountPath(accountPath)) {
|
|
1300
|
-
return (0,
|
|
1362
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1301
1363
|
}
|
|
1302
1364
|
try {
|
|
1303
|
-
return await this._jobQueue.enqueue(
|
|
1365
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1304
1366
|
const { account } = await this._fetchAccount(
|
|
1305
1367
|
connectId,
|
|
1306
1368
|
deviceId,
|
|
@@ -1311,8 +1373,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1311
1373
|
);
|
|
1312
1374
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1313
1375
|
if (!account.extendedPublicKey) {
|
|
1314
|
-
throw (0,
|
|
1315
|
-
code:
|
|
1376
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1377
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1316
1378
|
message: "Keystone did not return an extended public key for this account path"
|
|
1317
1379
|
});
|
|
1318
1380
|
}
|
|
@@ -1321,7 +1383,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1321
1383
|
relativeDerivePath,
|
|
1322
1384
|
scriptType
|
|
1323
1385
|
);
|
|
1324
|
-
return (0,
|
|
1386
|
+
return (0, import_hwk_adapter_core4.success)({ address, path: normalizedPath });
|
|
1325
1387
|
});
|
|
1326
1388
|
} catch (err) {
|
|
1327
1389
|
return this._errorToFailure(err);
|
|
@@ -1342,21 +1404,21 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1342
1404
|
const connectId = operationTarget.payload.targetId;
|
|
1343
1405
|
const deviceId = deviceIdArg ?? void 0;
|
|
1344
1406
|
const params = paramsArg;
|
|
1345
|
-
if (!params) return (0,
|
|
1407
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcGetPublicKey requires params");
|
|
1346
1408
|
if (!params.path)
|
|
1347
|
-
return (0,
|
|
1409
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcGetPublicKey requires params.path");
|
|
1348
1410
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1349
1411
|
if (relativeDerivePath) {
|
|
1350
|
-
return (0,
|
|
1351
|
-
|
|
1412
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1413
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1352
1414
|
"btcGetPublicKey requires an account path, e.g. m/84'/0'/0' (not a leaf path)"
|
|
1353
1415
|
);
|
|
1354
1416
|
}
|
|
1355
1417
|
if (!isKeystoneSignableBtcAccountPath(accountPath)) {
|
|
1356
|
-
return (0,
|
|
1418
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1357
1419
|
}
|
|
1358
1420
|
try {
|
|
1359
|
-
return await this._jobQueue.enqueue(
|
|
1421
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1360
1422
|
const { account } = await this._fetchAccount(
|
|
1361
1423
|
connectId,
|
|
1362
1424
|
deviceId,
|
|
@@ -1367,13 +1429,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1367
1429
|
);
|
|
1368
1430
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1369
1431
|
if (!account.extendedPublicKey) {
|
|
1370
|
-
throw (0,
|
|
1371
|
-
code:
|
|
1432
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1433
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1372
1434
|
message: "Keystone did not return an extended public key for this account path"
|
|
1373
1435
|
});
|
|
1374
1436
|
}
|
|
1375
1437
|
const meta = this.urEngine.parseXpubMeta(account.extendedPublicKey);
|
|
1376
|
-
return (0,
|
|
1438
|
+
return (0, import_hwk_adapter_core4.success)({
|
|
1377
1439
|
xpub: account.extendedPublicKey,
|
|
1378
1440
|
publicKey: meta.publicKey,
|
|
1379
1441
|
chainCode: meta.chainCode,
|
|
@@ -1398,17 +1460,19 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1398
1460
|
const connectId = operationTarget.payload.targetId;
|
|
1399
1461
|
const deviceId = deviceIdArg ?? void 0;
|
|
1400
1462
|
const params = paramsArg;
|
|
1401
|
-
if (!params) return (0,
|
|
1463
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params");
|
|
1402
1464
|
if (!params.psbt)
|
|
1403
|
-
return (0,
|
|
1404
|
-
if (
|
|
1405
|
-
return (0,
|
|
1465
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params.psbt");
|
|
1466
|
+
if (!params.path)
|
|
1467
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params.path");
|
|
1468
|
+
if (!isKeystoneSignableBtcAccountPath(splitAccountPath(params.path).accountPath)) {
|
|
1469
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1406
1470
|
}
|
|
1407
1471
|
try {
|
|
1408
|
-
return await this._jobQueue.enqueue(
|
|
1472
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1409
1473
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1410
1474
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1411
|
-
const requestUr = this.urEngine.buildBtcPsbtRequest((0,
|
|
1475
|
+
const requestUr = this.urEngine.buildBtcPsbtRequest((0, import_hwk_adapter_core4.stripHex)(params.psbt));
|
|
1412
1476
|
const responseUr = await this._resolveUr(
|
|
1413
1477
|
record,
|
|
1414
1478
|
requestUr,
|
|
@@ -1419,7 +1483,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1419
1483
|
);
|
|
1420
1484
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1421
1485
|
const signedPsbt = this.urEngine.parseBtcPsbt(responseUr);
|
|
1422
|
-
return (0,
|
|
1486
|
+
return (0, import_hwk_adapter_core4.success)({ signedPsbt });
|
|
1423
1487
|
});
|
|
1424
1488
|
} catch (err) {
|
|
1425
1489
|
return this._errorToFailure(err);
|
|
@@ -1431,27 +1495,28 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1431
1495
|
const connectId = operationTarget.payload.targetId;
|
|
1432
1496
|
const deviceId = deviceIdArg ?? void 0;
|
|
1433
1497
|
const params = paramsArg;
|
|
1434
|
-
if (!params) return (0,
|
|
1498
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignMessage requires params");
|
|
1435
1499
|
if (!params.path || params.message === void 0) {
|
|
1436
|
-
return (0,
|
|
1437
|
-
|
|
1500
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1501
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1438
1502
|
"btcSignMessage requires params.path and params.message"
|
|
1439
1503
|
);
|
|
1440
1504
|
}
|
|
1441
|
-
const messageHex = params.hex ? (0,
|
|
1505
|
+
const messageHex = params.hex ? (0, import_hwk_adapter_core4.stripHex)(params.message) : Buffer.from(params.message, "utf8").toString("hex");
|
|
1442
1506
|
const path = normalizePath(params.path);
|
|
1443
1507
|
if (!isKeystoneSignableBtcAccountPath(splitAccountPath(path).accountPath)) {
|
|
1444
|
-
return (0,
|
|
1508
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1445
1509
|
}
|
|
1446
1510
|
try {
|
|
1447
|
-
return await this._jobQueue.enqueue(
|
|
1511
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1448
1512
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1449
1513
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1450
1514
|
const requestId = (0, import_uuid2.v4)();
|
|
1451
1515
|
const requestUr = this.urEngine.buildBtcMessageSignRequest({
|
|
1452
1516
|
requestId,
|
|
1453
1517
|
messageHex,
|
|
1454
|
-
accounts: [{ path, xfp: record.masterFingerprint }]
|
|
1518
|
+
accounts: [{ path, xfp: record.masterFingerprint }],
|
|
1519
|
+
origin: this._origin
|
|
1455
1520
|
});
|
|
1456
1521
|
const responseUr = await this._resolveUr(
|
|
1457
1522
|
record,
|
|
@@ -1464,7 +1529,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1464
1529
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1465
1530
|
const sig = this.urEngine.parseBtcSignature(responseUr);
|
|
1466
1531
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1467
|
-
return (0,
|
|
1532
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1468
1533
|
});
|
|
1469
1534
|
} catch (err) {
|
|
1470
1535
|
return this._errorToFailure(err);
|
|
@@ -1476,9 +1541,9 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1476
1541
|
const connectId = operationTarget.payload.targetId;
|
|
1477
1542
|
const deviceId = deviceIdArg ?? void 0;
|
|
1478
1543
|
try {
|
|
1479
|
-
return await this._jobQueue.enqueue(
|
|
1544
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1480
1545
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1481
|
-
return (0,
|
|
1546
|
+
return (0, import_hwk_adapter_core4.success)({ masterFingerprint: record.masterFingerprint });
|
|
1482
1547
|
});
|
|
1483
1548
|
} catch (err) {
|
|
1484
1549
|
return this._errorToFailure(err);
|
|
@@ -1493,18 +1558,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1493
1558
|
const connectId = operationTarget.payload.targetId;
|
|
1494
1559
|
const deviceId = deviceIdArg ?? void 0;
|
|
1495
1560
|
const params = paramsArg;
|
|
1496
|
-
if (!params) return (0,
|
|
1561
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solGetAddress requires params");
|
|
1497
1562
|
if (!params.path)
|
|
1498
|
-
return (0,
|
|
1563
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solGetAddress requires params.path");
|
|
1499
1564
|
const path = normalizePath(params.path);
|
|
1500
1565
|
try {
|
|
1501
|
-
return await this._jobQueue.enqueue(
|
|
1566
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1502
1567
|
const { account } = await this._fetchAccount(connectId, deviceId, "sol", path, signal, {
|
|
1503
1568
|
book
|
|
1504
1569
|
});
|
|
1505
1570
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1506
1571
|
const address = import_bs58.default.encode(Buffer.from(account.publicKey, "hex"));
|
|
1507
|
-
return (0,
|
|
1572
|
+
return (0, import_hwk_adapter_core4.success)({ address, path });
|
|
1508
1573
|
});
|
|
1509
1574
|
} catch (err) {
|
|
1510
1575
|
return this._errorToFailure(err);
|
|
@@ -1517,25 +1582,26 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1517
1582
|
const deviceId = deviceIdArg ?? void 0;
|
|
1518
1583
|
const params = paramsArg;
|
|
1519
1584
|
if (!params)
|
|
1520
|
-
return (0,
|
|
1585
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solSignTransaction requires params");
|
|
1521
1586
|
if (!params.path || !params.serializedTx) {
|
|
1522
|
-
return (0,
|
|
1523
|
-
|
|
1587
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1588
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1524
1589
|
"solSignTransaction requires params.path and params.serializedTx"
|
|
1525
1590
|
);
|
|
1526
1591
|
}
|
|
1527
1592
|
const path = normalizePath(params.path);
|
|
1528
1593
|
try {
|
|
1529
|
-
return await this._jobQueue.enqueue(
|
|
1594
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1530
1595
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "sol", signal);
|
|
1531
1596
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1532
1597
|
const requestId = (0, import_uuid2.v4)();
|
|
1533
1598
|
const requestUr = this.urEngine.buildSolSignRequest({
|
|
1534
1599
|
requestId,
|
|
1535
|
-
unsignedPayloadHex: (0,
|
|
1600
|
+
unsignedPayloadHex: (0, import_hwk_adapter_core4.stripHex)(params.serializedTx),
|
|
1536
1601
|
dataType: "transaction",
|
|
1537
1602
|
path,
|
|
1538
|
-
xfp: record.masterFingerprint
|
|
1603
|
+
xfp: record.masterFingerprint,
|
|
1604
|
+
origin: this._origin
|
|
1539
1605
|
});
|
|
1540
1606
|
const responseUr = await this._resolveUr(
|
|
1541
1607
|
record,
|
|
@@ -1548,7 +1614,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1548
1614
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1549
1615
|
const sig = this.urEngine.parseSolSignature(responseUr);
|
|
1550
1616
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1551
|
-
return (0,
|
|
1617
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1552
1618
|
});
|
|
1553
1619
|
} catch (err) {
|
|
1554
1620
|
return this._errorToFailure(err);
|
|
@@ -1560,25 +1626,26 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1560
1626
|
const connectId = operationTarget.payload.targetId;
|
|
1561
1627
|
const deviceId = deviceIdArg ?? void 0;
|
|
1562
1628
|
const params = paramsArg;
|
|
1563
|
-
if (!params) return (0,
|
|
1629
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solSignMessage requires params");
|
|
1564
1630
|
if (!params.path || !params.message) {
|
|
1565
|
-
return (0,
|
|
1566
|
-
|
|
1631
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1632
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1567
1633
|
"solSignMessage requires params.path and params.message"
|
|
1568
1634
|
);
|
|
1569
1635
|
}
|
|
1570
1636
|
const path = normalizePath(params.path);
|
|
1571
1637
|
try {
|
|
1572
|
-
return await this._jobQueue.enqueue(
|
|
1638
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1573
1639
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "sol", signal);
|
|
1574
1640
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1575
1641
|
const requestId = (0, import_uuid2.v4)();
|
|
1576
1642
|
const requestUr = this.urEngine.buildSolSignRequest({
|
|
1577
1643
|
requestId,
|
|
1578
|
-
unsignedPayloadHex: (0,
|
|
1644
|
+
unsignedPayloadHex: (0, import_hwk_adapter_core4.stripHex)(params.message),
|
|
1579
1645
|
dataType: "message",
|
|
1580
1646
|
path,
|
|
1581
|
-
xfp: record.masterFingerprint
|
|
1647
|
+
xfp: record.masterFingerprint,
|
|
1648
|
+
origin: this._origin
|
|
1582
1649
|
});
|
|
1583
1650
|
const responseUr = await this._resolveUr(
|
|
1584
1651
|
record,
|
|
@@ -1591,7 +1658,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1591
1658
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1592
1659
|
const sig = this.urEngine.parseSolSignature(responseUr);
|
|
1593
1660
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1594
|
-
return (0,
|
|
1661
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1595
1662
|
});
|
|
1596
1663
|
} catch (err) {
|
|
1597
1664
|
return this._errorToFailure(err);
|
|
@@ -1599,10 +1666,11 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1599
1666
|
}
|
|
1600
1667
|
// ---------------------------------------------------------------------------
|
|
1601
1668
|
// TRON — routed through `TronSignRequest`/`TronSignature` (see
|
|
1602
|
-
// urEngine/TronSignRequest.ts),
|
|
1603
|
-
//
|
|
1604
|
-
//
|
|
1605
|
-
// unverified response
|
|
1669
|
+
// urEngine/TronSignRequest.ts), whose key layout follows keystone-sdk-rust
|
|
1670
|
+
// (tags 5201/5202, firmware >= 2.5.0). The OneKey Pro air-gap encoding under
|
|
1671
|
+
// the same tag is a different layout the firmware rejects. Not keystone-sdk's
|
|
1672
|
+
// bundled `sdk.tron` module either (protobuf-based, unverified response
|
|
1673
|
+
// semantics).
|
|
1606
1674
|
// ---------------------------------------------------------------------------
|
|
1607
1675
|
async tronGetAddress(connectIdArg, deviceIdArg, paramsArg, book) {
|
|
1608
1676
|
const operationTarget = resolveHardwareOperationTarget(connectIdArg, paramsArg?.operationId);
|
|
@@ -1610,18 +1678,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1610
1678
|
const connectId = operationTarget.payload.targetId;
|
|
1611
1679
|
const deviceId = deviceIdArg ?? void 0;
|
|
1612
1680
|
const params = paramsArg;
|
|
1613
|
-
if (!params) return (0,
|
|
1681
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronGetAddress requires params");
|
|
1614
1682
|
if (!params.path)
|
|
1615
|
-
return (0,
|
|
1683
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronGetAddress requires params.path");
|
|
1616
1684
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1617
1685
|
if (!relativeDerivePath) {
|
|
1618
|
-
return (0,
|
|
1619
|
-
|
|
1686
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1687
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1620
1688
|
"tronGetAddress requires a full leaf path, e.g. m/44'/195'/0'/0/0"
|
|
1621
1689
|
);
|
|
1622
1690
|
}
|
|
1623
1691
|
try {
|
|
1624
|
-
return await this._jobQueue.enqueue(
|
|
1692
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1625
1693
|
const { account } = await this._fetchAccount(
|
|
1626
1694
|
connectId,
|
|
1627
1695
|
deviceId,
|
|
@@ -1632,8 +1700,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1632
1700
|
);
|
|
1633
1701
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1634
1702
|
if (!account.extendedPublicKey) {
|
|
1635
|
-
throw (0,
|
|
1636
|
-
code:
|
|
1703
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1704
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1637
1705
|
message: "Keystone did not return an extended public key for this account path"
|
|
1638
1706
|
});
|
|
1639
1707
|
}
|
|
@@ -1641,7 +1709,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1641
1709
|
account.extendedPublicKey,
|
|
1642
1710
|
relativeDerivePath
|
|
1643
1711
|
);
|
|
1644
|
-
return (0,
|
|
1712
|
+
return (0, import_hwk_adapter_core4.success)({ address, path: normalizePath(params.path) });
|
|
1645
1713
|
});
|
|
1646
1714
|
} catch (err) {
|
|
1647
1715
|
return this._errorToFailure(err);
|
|
@@ -1654,20 +1722,20 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1654
1722
|
const deviceId = deviceIdArg ?? void 0;
|
|
1655
1723
|
const params = paramsArg;
|
|
1656
1724
|
if (!params)
|
|
1657
|
-
return (0,
|
|
1725
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignTransaction requires params");
|
|
1658
1726
|
if (!params.path) {
|
|
1659
|
-
return (0,
|
|
1727
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignTransaction requires params.path");
|
|
1660
1728
|
}
|
|
1661
1729
|
if (!params.rawTxHex) {
|
|
1662
|
-
return (0,
|
|
1663
|
-
|
|
1730
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1731
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1664
1732
|
"Keystone only signs a fully protobuf-serialized TRON transaction (params.rawTxHex) \u2014 the Trezor-style structured contract fields have no equivalent here"
|
|
1665
1733
|
);
|
|
1666
1734
|
}
|
|
1667
|
-
const rawTxHex = (0,
|
|
1735
|
+
const rawTxHex = (0, import_hwk_adapter_core4.stripHex)(params.rawTxHex);
|
|
1668
1736
|
const path = normalizePath(params.path);
|
|
1669
1737
|
try {
|
|
1670
|
-
return await this._jobQueue.enqueue(
|
|
1738
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1671
1739
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "tron", signal);
|
|
1672
1740
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1673
1741
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1675,7 +1743,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1675
1743
|
requestId,
|
|
1676
1744
|
rawTxHex,
|
|
1677
1745
|
path,
|
|
1678
|
-
xfp: record.masterFingerprint
|
|
1746
|
+
xfp: record.masterFingerprint,
|
|
1747
|
+
origin: this._origin
|
|
1679
1748
|
});
|
|
1680
1749
|
const responseUr = await this._resolveUr(
|
|
1681
1750
|
record,
|
|
@@ -1688,7 +1757,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1688
1757
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1689
1758
|
const sig = this.urEngine.parseTronSignature(responseUr);
|
|
1690
1759
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1691
|
-
return (0,
|
|
1760
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1692
1761
|
});
|
|
1693
1762
|
} catch (err) {
|
|
1694
1763
|
return this._errorToFailure(err);
|
|
@@ -1700,23 +1769,23 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1700
1769
|
const connectId = operationTarget.payload.targetId;
|
|
1701
1770
|
const deviceId = deviceIdArg ?? void 0;
|
|
1702
1771
|
const params = paramsArg;
|
|
1703
|
-
if (!params) return (0,
|
|
1772
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignMessage requires params");
|
|
1704
1773
|
if (!params.path) {
|
|
1705
|
-
return (0,
|
|
1774
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignMessage requires params.path");
|
|
1706
1775
|
}
|
|
1707
1776
|
if (!params.messageHex) {
|
|
1708
|
-
return (0,
|
|
1777
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignMessage requires params.messageHex");
|
|
1709
1778
|
}
|
|
1710
1779
|
if (params.messageType !== "V2") {
|
|
1711
|
-
return (0,
|
|
1712
|
-
|
|
1780
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1781
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1713
1782
|
'Keystone signs TRON messages as TIP-191 signMessageV2 only (messageType: "V2")'
|
|
1714
1783
|
);
|
|
1715
1784
|
}
|
|
1716
|
-
const messageHex = (0,
|
|
1785
|
+
const messageHex = (0, import_hwk_adapter_core4.stripHex)(params.messageHex);
|
|
1717
1786
|
const path = normalizePath(params.path);
|
|
1718
1787
|
try {
|
|
1719
|
-
return await this._jobQueue.enqueue(
|
|
1788
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1720
1789
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "tron", signal);
|
|
1721
1790
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1722
1791
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1725,7 +1794,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1725
1794
|
rawTxHex: messageHex,
|
|
1726
1795
|
path,
|
|
1727
1796
|
xfp: record.masterFingerprint,
|
|
1728
|
-
signType: 2 /* PersonalMessage
|
|
1797
|
+
signType: 2 /* PersonalMessage */,
|
|
1798
|
+
origin: this._origin
|
|
1729
1799
|
});
|
|
1730
1800
|
const responseUr = await this._resolveUr(
|
|
1731
1801
|
record,
|
|
@@ -1738,7 +1808,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1738
1808
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1739
1809
|
const sig = this.urEngine.parseTronSignature(responseUr);
|
|
1740
1810
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1741
|
-
return (0,
|
|
1811
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1742
1812
|
});
|
|
1743
1813
|
} catch (err) {
|
|
1744
1814
|
return this._errorToFailure(err);
|
|
@@ -1748,13 +1818,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1748
1818
|
// Internals
|
|
1749
1819
|
// ---------------------------------------------------------------------------
|
|
1750
1820
|
_walletIdFromIdentifier(identifier) {
|
|
1751
|
-
|
|
1752
|
-
return /^[0-9a-f]{64}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
1821
|
+
return keystoneWalletIdFromIdentifier(identifier);
|
|
1753
1822
|
}
|
|
1754
1823
|
_allNetworkSyncSchema(item) {
|
|
1755
|
-
if (!(0,
|
|
1824
|
+
if (!(0, import_hwk_adapter_core4.isAllNetworkMethodName)(String(item.methodName)) || !item.path) return void 0;
|
|
1756
1825
|
const method = item.methodName;
|
|
1757
|
-
const hwkChain = (0,
|
|
1826
|
+
const hwkChain = (0, import_hwk_adapter_core4.getAllNetworkMethodChain)(method);
|
|
1758
1827
|
const path = normalizePath(item.path);
|
|
1759
1828
|
if (hwkChain === "btc" && !isKeystoneSignableBtcAccountPath(splitAccountPath(path).accountPath)) {
|
|
1760
1829
|
return void 0;
|
|
@@ -1778,7 +1847,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1778
1847
|
* one-path-at-a-time export flow because the device limits that channel.
|
|
1779
1848
|
*/
|
|
1780
1849
|
async _prefetchAllNetworkAccounts(connectId, deviceId, params) {
|
|
1781
|
-
return this._jobQueue.enqueue(
|
|
1850
|
+
return this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1782
1851
|
const target = this._resolveTarget(connectId, deviceId);
|
|
1783
1852
|
const { record: targetRecord } = target;
|
|
1784
1853
|
let record = targetRecord;
|
|
@@ -1791,19 +1860,22 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1791
1860
|
if (!requestedByKey.size) {
|
|
1792
1861
|
return { book };
|
|
1793
1862
|
}
|
|
1794
|
-
|
|
1863
|
+
const operation = (0, import_hwk_adapter_core4.isHardwareOperationId)(params.operationId) ? this._operations.find(params.operationId) : void 0;
|
|
1864
|
+
const operationRoute = operation ? this._operationRoutes.get(operation.connectId) : void 0;
|
|
1865
|
+
const routedToQr = operationRoute?.operationId === operation?.operationId && operationRoute?.connectionType === "qr";
|
|
1866
|
+
if (this._forcedTransport !== "qr" && !routedToQr && !record?.usbSessionId && this._usbConnector && target.expectedWalletId) {
|
|
1795
1867
|
record = await this._tryUsbAttach(
|
|
1796
1868
|
target.expectedWalletId,
|
|
1797
1869
|
record?.masterFingerprint ?? target.expectedMasterFingerprint
|
|
1798
1870
|
) ?? record;
|
|
1799
1871
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1800
1872
|
}
|
|
1801
|
-
if (this._forcedTransport !== "qr" && record?.usbSessionId) {
|
|
1873
|
+
if (this._forcedTransport !== "qr" && !routedToQr && record?.usbSessionId) {
|
|
1802
1874
|
const bundleSessionId = record.usbSessionId;
|
|
1803
1875
|
const assertBundleSession = () => {
|
|
1804
1876
|
if (record?.usbSessionId !== bundleSessionId) {
|
|
1805
|
-
throw (0,
|
|
1806
|
-
code:
|
|
1877
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1878
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
1807
1879
|
message: "Keystone USB connection was lost during account export"
|
|
1808
1880
|
});
|
|
1809
1881
|
}
|
|
@@ -1826,8 +1898,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1826
1898
|
}
|
|
1827
1899
|
for (const schema of missingSchemas2) {
|
|
1828
1900
|
if (!book.has(accountKey(schema.hwkChain, schema.path))) {
|
|
1829
|
-
throw (0,
|
|
1830
|
-
code:
|
|
1901
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1902
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1831
1903
|
message: `Keystone did not return the requested derivation path (${schema.path})`
|
|
1832
1904
|
});
|
|
1833
1905
|
}
|
|
@@ -1835,8 +1907,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1835
1907
|
return { book, walletId: record.walletId };
|
|
1836
1908
|
}
|
|
1837
1909
|
if (this._forcedTransport === "usb") {
|
|
1838
|
-
throw (0,
|
|
1839
|
-
code:
|
|
1910
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1911
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
1840
1912
|
message: "USB channel is not connected for this Keystone wallet"
|
|
1841
1913
|
});
|
|
1842
1914
|
}
|
|
@@ -1854,7 +1926,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1854
1926
|
});
|
|
1855
1927
|
const responseUr = await this._requestQrDisplayAndAwaitResponse(
|
|
1856
1928
|
record ? toDeviceInfo(record) : placeholderDeviceInfo(),
|
|
1857
|
-
{ ...requestUr, animated: false }
|
|
1929
|
+
{ ...requestUr, animated: false },
|
|
1930
|
+
signal
|
|
1858
1931
|
);
|
|
1859
1932
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1860
1933
|
const parsed = this.urEngine.parseAccountResponse(responseUr);
|
|
@@ -1875,8 +1948,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1875
1948
|
}
|
|
1876
1949
|
for (const schema of missingSchemas) {
|
|
1877
1950
|
if (!book.has(accountKey(schema.hwkChain, schema.path))) {
|
|
1878
|
-
throw (0,
|
|
1879
|
-
code:
|
|
1951
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1952
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1880
1953
|
message: `Keystone did not return the requested derivation path (${schema.path})`
|
|
1881
1954
|
});
|
|
1882
1955
|
}
|
|
@@ -1890,7 +1963,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1890
1963
|
*/
|
|
1891
1964
|
_resolveTarget(connectId, deviceId) {
|
|
1892
1965
|
let resolvedConnectId = connectId;
|
|
1893
|
-
if ((0,
|
|
1966
|
+
if ((0, import_hwk_adapter_core4.isHardwareOperationId)(connectId)) {
|
|
1894
1967
|
resolvedConnectId = this._operations.resolve(connectId).connectId;
|
|
1895
1968
|
}
|
|
1896
1969
|
const identifiers = [deviceId, resolvedConnectId].filter(
|
|
@@ -1899,21 +1972,21 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1899
1972
|
if (!identifiers.length) return {};
|
|
1900
1973
|
const walletIds = identifiers.map((identifier) => this._walletIdFromIdentifier(identifier)).filter((walletId) => Boolean(walletId));
|
|
1901
1974
|
if (!walletIds.length) {
|
|
1902
|
-
throw (0,
|
|
1903
|
-
code:
|
|
1975
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1976
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceNotFound,
|
|
1904
1977
|
message: "Keystone device lookup requires a 64-hex wallet identity"
|
|
1905
1978
|
});
|
|
1906
1979
|
}
|
|
1907
1980
|
const expectedWalletId = walletIds[0];
|
|
1908
1981
|
if (walletIds.some((walletId) => walletId !== expectedWalletId)) {
|
|
1909
|
-
throw (0,
|
|
1910
|
-
code:
|
|
1982
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1983
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1911
1984
|
message: "Keystone connectId and deviceId identify different wallets"
|
|
1912
1985
|
});
|
|
1913
1986
|
}
|
|
1914
1987
|
if (identifiers.some((identifier) => !this._walletIdFromIdentifier(identifier))) {
|
|
1915
|
-
throw (0,
|
|
1916
|
-
code:
|
|
1988
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1989
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1917
1990
|
message: "Keystone connectId and deviceId are inconsistent"
|
|
1918
1991
|
});
|
|
1919
1992
|
}
|
|
@@ -1927,14 +2000,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1927
2000
|
_assertParsedIdentity(parsed, expected) {
|
|
1928
2001
|
const walletId = deriveKeystoneWalletId(parsed.accounts);
|
|
1929
2002
|
if (expected.expectedMasterFingerprint && parsed.masterFingerprint !== expected.expectedMasterFingerprint) {
|
|
1930
|
-
throw (0,
|
|
1931
|
-
code:
|
|
2003
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2004
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1932
2005
|
message: `Connected Keystone wallet (mfp ${parsed.masterFingerprint}) does not match the requested wallet fingerprint (${expected.expectedMasterFingerprint})`
|
|
1933
2006
|
});
|
|
1934
2007
|
}
|
|
1935
2008
|
if (expected.expectedWalletId && walletId !== expected.expectedWalletId) {
|
|
1936
|
-
throw (0,
|
|
1937
|
-
code:
|
|
2009
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2010
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1938
2011
|
message: "Connected Keystone wallet does not match the requested wallet identity"
|
|
1939
2012
|
});
|
|
1940
2013
|
}
|
|
@@ -1957,8 +2030,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1957
2030
|
record = createDeviceRecord(walletId, parsed.masterFingerprint);
|
|
1958
2031
|
this._devices.set(walletId, record);
|
|
1959
2032
|
} else if (record.masterFingerprint !== parsed.masterFingerprint) {
|
|
1960
|
-
throw (0,
|
|
1961
|
-
code:
|
|
2033
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2034
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1962
2035
|
message: "Keystone wallet identity returned an inconsistent master fingerprint"
|
|
1963
2036
|
});
|
|
1964
2037
|
}
|
|
@@ -1968,7 +2041,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1968
2041
|
record.usbSessionId = options?.usbSessionId ?? record.usbSessionId;
|
|
1969
2042
|
if (!options?.viaUsb) record.qrSynced = true;
|
|
1970
2043
|
const info = toDeviceInfo(record);
|
|
1971
|
-
const eventType = isNew ?
|
|
2044
|
+
const eventType = isNew ? import_hwk_adapter_core4.DEVICE.CONNECT : import_hwk_adapter_core4.DEVICE.CHANGED;
|
|
1972
2045
|
this.emitter.emit(eventType, { type: eventType, payload: info });
|
|
1973
2046
|
return record;
|
|
1974
2047
|
}
|
|
@@ -1983,8 +2056,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1983
2056
|
*/
|
|
1984
2057
|
async _connectUsb(expected, searchTargetId) {
|
|
1985
2058
|
if (this._pendingUsbTeardowns > 0) {
|
|
1986
|
-
return (0,
|
|
1987
|
-
|
|
2059
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2060
|
+
import_hwk_adapter_core4.HardwareErrorCode.DeviceBusyInternal,
|
|
1988
2061
|
"Keystone USB session is being released"
|
|
1989
2062
|
);
|
|
1990
2063
|
}
|
|
@@ -2002,8 +2075,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2002
2075
|
}
|
|
2003
2076
|
async _connectUsbExclusive(expected, searchTargetId) {
|
|
2004
2077
|
if (!this._usbConnector) {
|
|
2005
|
-
return (0,
|
|
2006
|
-
|
|
2078
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2079
|
+
import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
2007
2080
|
"No USB connector configured for this Keystone adapter"
|
|
2008
2081
|
);
|
|
2009
2082
|
}
|
|
@@ -2022,17 +2095,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2022
2095
|
const session = await (connector.connectTarget ? connector.connectTarget(connectTarget) : connector.connect(searchTargetId ?? expected.expectedMasterFingerprint));
|
|
2023
2096
|
sessionId = session.sessionId;
|
|
2024
2097
|
const raw = session.deviceInfo.raw;
|
|
2025
|
-
const mfpValue = (0,
|
|
2098
|
+
const mfpValue = (0, import_hwk_adapter_core4.parseBip32MasterFingerprint)(raw?.masterFingerprint);
|
|
2026
2099
|
if (!mfpValue) {
|
|
2027
|
-
throw (0,
|
|
2028
|
-
code:
|
|
2100
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2101
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2029
2102
|
message: "Keystone USB did not report a master fingerprint"
|
|
2030
2103
|
});
|
|
2031
2104
|
}
|
|
2032
2105
|
const masterFingerprint = mfpValue.toLowerCase();
|
|
2033
2106
|
if (expected.expectedMasterFingerprint && masterFingerprint !== expected.expectedMasterFingerprint) {
|
|
2034
|
-
throw (0,
|
|
2035
|
-
code:
|
|
2107
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2108
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2036
2109
|
message: `Connected Keystone wallet (mfp ${masterFingerprint}) does not match the requested wallet fingerprint (${expected.expectedMasterFingerprint})`
|
|
2037
2110
|
});
|
|
2038
2111
|
}
|
|
@@ -2046,7 +2119,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2046
2119
|
identityRequest
|
|
2047
2120
|
);
|
|
2048
2121
|
if (!identityResult.success) {
|
|
2049
|
-
throw (0,
|
|
2122
|
+
throw (0, import_hwk_adapter_core4.rehydrateConnectorError)(identityResult.error);
|
|
2050
2123
|
}
|
|
2051
2124
|
const parsed = this.urEngine.parseAccountResponse(identityResult.payload);
|
|
2052
2125
|
this._assertParsedIdentity(parsed, {
|
|
@@ -2069,7 +2142,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2069
2142
|
record.model = session.deviceInfo.modelName ?? session.deviceInfo.model ?? record.model;
|
|
2070
2143
|
record.deviceVersion = session.deviceInfo.firmwareVersion ?? record.deviceVersion;
|
|
2071
2144
|
const info = toDeviceInfo(record);
|
|
2072
|
-
return (0,
|
|
2145
|
+
return (0, import_hwk_adapter_core4.success)(info);
|
|
2073
2146
|
} catch (err) {
|
|
2074
2147
|
if (sessionId) {
|
|
2075
2148
|
try {
|
|
@@ -2140,7 +2213,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2140
2213
|
* closed rather than silently falling back to QR.
|
|
2141
2214
|
*/
|
|
2142
2215
|
async _resolveUr(record, requestUr, animated, operationId, signal, operationName) {
|
|
2143
|
-
const releaseOperationRetention = (0,
|
|
2216
|
+
const releaseOperationRetention = (0, import_hwk_adapter_core4.isHardwareOperationId)(operationId) ? this._operations.retain(operationId) : void 0;
|
|
2144
2217
|
try {
|
|
2145
2218
|
return await this._resolveUrWithRoute(
|
|
2146
2219
|
record,
|
|
@@ -2156,13 +2229,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2156
2229
|
}
|
|
2157
2230
|
async _resolveUrWithRoute(record, requestUr, animated, operationId, signal, operationName) {
|
|
2158
2231
|
let interactionRoute;
|
|
2159
|
-
if ((0,
|
|
2232
|
+
if ((0, import_hwk_adapter_core4.isHardwareOperationId)(operationId)) {
|
|
2160
2233
|
const operation = this._operations.resolve(operationId);
|
|
2161
2234
|
const route = this._operationRoutes.get(operation.connectId);
|
|
2162
2235
|
if (!route || route.operationId !== operationId) {
|
|
2163
2236
|
this._operations.end(operationId, "disconnect");
|
|
2164
|
-
throw (0,
|
|
2165
|
-
code:
|
|
2237
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2238
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationEnded,
|
|
2166
2239
|
message: "Keystone hardware operation is no longer connected",
|
|
2167
2240
|
params: { operationId, reason: "disconnect" }
|
|
2168
2241
|
});
|
|
@@ -2179,8 +2252,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2179
2252
|
if (!record?.usbSessionId || !this._usbConnector) {
|
|
2180
2253
|
if (interactionRoute) {
|
|
2181
2254
|
this._operations.end(interactionRoute.operationId, "disconnect");
|
|
2182
|
-
throw (0,
|
|
2183
|
-
code:
|
|
2255
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2256
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationEnded,
|
|
2184
2257
|
message: "Keystone operation USB connection was lost",
|
|
2185
2258
|
params: {
|
|
2186
2259
|
operationId: interactionRoute.operationId,
|
|
@@ -2188,8 +2261,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2188
2261
|
}
|
|
2189
2262
|
});
|
|
2190
2263
|
}
|
|
2191
|
-
throw (0,
|
|
2192
|
-
code:
|
|
2264
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2265
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
2193
2266
|
message: "USB channel is not connected for this Keystone wallet"
|
|
2194
2267
|
});
|
|
2195
2268
|
}
|
|
@@ -2200,17 +2273,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2200
2273
|
signal
|
|
2201
2274
|
);
|
|
2202
2275
|
if (result.success) return result.payload;
|
|
2203
|
-
const usbError = (0,
|
|
2276
|
+
const usbError = (0, import_hwk_adapter_core4.rehydrateConnectorError)(result.error);
|
|
2204
2277
|
const usbErrorOrigin = usbError.origin;
|
|
2205
2278
|
const usbErrorCode = usbError.code;
|
|
2206
|
-
if (!interactionRoute && !this._forcedTransport && usbErrorCode ===
|
|
2279
|
+
if (!interactionRoute && !this._forcedTransport && usbErrorCode === import_hwk_adapter_core4.HardwareErrorCode.PayloadTooLarge && usbErrorOrigin !== "device") {
|
|
2207
2280
|
const displayDevice2 = toDeviceInfo(record);
|
|
2208
|
-
return this._requestQrDisplayAndAwaitResponse(
|
|
2209
|
-
|
|
2210
|
-
animated
|
|
2211
|
-
|
|
2281
|
+
return this._requestQrDisplayAndAwaitResponse(
|
|
2282
|
+
displayDevice2,
|
|
2283
|
+
{ ...requestUr, animated },
|
|
2284
|
+
signal
|
|
2285
|
+
);
|
|
2212
2286
|
}
|
|
2213
|
-
const deviceAnswered = usbErrorOrigin !== void 0 ? usbErrorOrigin === "device" : usbErrorCode ===
|
|
2287
|
+
const deviceAnswered = usbErrorOrigin !== void 0 ? usbErrorOrigin === "device" : usbErrorCode === import_hwk_adapter_core4.HardwareErrorCode.UserRejected || usbErrorCode === import_hwk_adapter_core4.HardwareErrorCode.UserAborted || usbErrorCode === import_hwk_adapter_core4.HardwareErrorCode.DeviceLocked || usbErrorCode === import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch;
|
|
2214
2288
|
if (!deviceAnswered) {
|
|
2215
2289
|
const lostSessionId = record.usbSessionId;
|
|
2216
2290
|
if (lostSessionId) {
|
|
@@ -2219,11 +2293,11 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2219
2293
|
record.usbSessionId = void 0;
|
|
2220
2294
|
if (interactionRoute) {
|
|
2221
2295
|
this._operations.end(interactionRoute.operationId, "disconnect");
|
|
2222
|
-
throw (0,
|
|
2223
|
-
code:
|
|
2296
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2297
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationEnded,
|
|
2224
2298
|
message: operationName ? `Keystone ${operationName} may have completed before the USB connection was lost` : "Keystone operation USB connection was lost",
|
|
2225
2299
|
recovery: operationName ? { scope: "unknown" } : void 0,
|
|
2226
|
-
params: operationName ? (0,
|
|
2300
|
+
params: operationName ? (0, import_hwk_adapter_core4.operationMayHaveCompletedParams)(operationName, {
|
|
2227
2301
|
operationId: interactionRoute.operationId,
|
|
2228
2302
|
reason: "disconnect"
|
|
2229
2303
|
}) : {
|
|
@@ -2233,12 +2307,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2233
2307
|
});
|
|
2234
2308
|
}
|
|
2235
2309
|
if (operationName) {
|
|
2236
|
-
throw (0,
|
|
2237
|
-
code: usbErrorCode ??
|
|
2310
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2311
|
+
code: usbErrorCode ?? import_hwk_adapter_core4.HardwareErrorCode.TransportError,
|
|
2238
2312
|
message: `Keystone ${operationName} may have completed before the USB connection was lost`,
|
|
2239
2313
|
origin: "transport",
|
|
2240
2314
|
recovery: { scope: "unknown" },
|
|
2241
|
-
params: (0,
|
|
2315
|
+
params: (0, import_hwk_adapter_core4.operationMayHaveCompletedParams)(operationName)
|
|
2242
2316
|
});
|
|
2243
2317
|
}
|
|
2244
2318
|
}
|
|
@@ -2246,18 +2320,19 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2246
2320
|
}
|
|
2247
2321
|
const displayDevice = record ? toDeviceInfo(record) : placeholderDeviceInfo();
|
|
2248
2322
|
try {
|
|
2249
|
-
return await this._requestQrDisplayAndAwaitResponse(
|
|
2250
|
-
|
|
2251
|
-
animated
|
|
2252
|
-
|
|
2323
|
+
return await this._requestQrDisplayAndAwaitResponse(
|
|
2324
|
+
displayDevice,
|
|
2325
|
+
{ ...requestUr, animated },
|
|
2326
|
+
signal
|
|
2327
|
+
);
|
|
2253
2328
|
} catch (error) {
|
|
2254
2329
|
const { code, _tag: tag } = error;
|
|
2255
|
-
if (operationName && (code ===
|
|
2256
|
-
throw (0,
|
|
2257
|
-
code:
|
|
2330
|
+
if (operationName && (code === import_hwk_adapter_core4.HardwareErrorCode.OperationTimeout || tag === import_hwk_adapter_core4.UI_REQUEST_TIMEOUT_TAG)) {
|
|
2331
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2332
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationTimeout,
|
|
2258
2333
|
message: `Keystone ${operationName} may have completed before the QR response timed out`,
|
|
2259
2334
|
recovery: { scope: "unknown" },
|
|
2260
|
-
params: (0,
|
|
2335
|
+
params: (0, import_hwk_adapter_core4.operationMayHaveCompletedParams)(operationName)
|
|
2261
2336
|
});
|
|
2262
2337
|
}
|
|
2263
2338
|
throw error;
|
|
@@ -2309,8 +2384,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2309
2384
|
let record;
|
|
2310
2385
|
if (resolvedViaUsb && existingRecord) {
|
|
2311
2386
|
if (parsed.masterFingerprint !== existingRecord.masterFingerprint) {
|
|
2312
|
-
throw (0,
|
|
2313
|
-
code:
|
|
2387
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2388
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2314
2389
|
message: "Keystone USB account export returned a different master fingerprint"
|
|
2315
2390
|
});
|
|
2316
2391
|
}
|
|
@@ -2323,8 +2398,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2323
2398
|
}
|
|
2324
2399
|
const account = parsed.accounts.find((a) => normalizePath(a.path) === syncPath);
|
|
2325
2400
|
if (!account) {
|
|
2326
|
-
throw (0,
|
|
2327
|
-
code:
|
|
2401
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2402
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2328
2403
|
message: `Keystone did not return the requested derivation path (${syncPath})`
|
|
2329
2404
|
});
|
|
2330
2405
|
}
|
|
@@ -2365,7 +2440,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2365
2440
|
const attached = await this._tryUsbAttach(target.expectedWalletId);
|
|
2366
2441
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2367
2442
|
if (attached) return { record: attached };
|
|
2368
|
-
const { accountPath } = splitAccountPath(
|
|
2443
|
+
const { accountPath } = splitAccountPath(import_hwk_adapter_core4.CHAIN_FINGERPRINT_PATHS[chain]);
|
|
2369
2444
|
const schemas = accountPath === KEYSTONE_WALLET_ID_PATH ? [{ path: KEYSTONE_WALLET_ID_PATH, curve: "secp256k1" }] : [
|
|
2370
2445
|
{ path: KEYSTONE_WALLET_ID_PATH, curve: "secp256k1" },
|
|
2371
2446
|
{
|
|
@@ -2384,43 +2459,97 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2384
2459
|
const record = this._upsertDeviceRecord(parsed);
|
|
2385
2460
|
return { record };
|
|
2386
2461
|
}
|
|
2387
|
-
|
|
2462
|
+
/**
|
|
2463
|
+
* The operation the running device job belongs to, so a UI request raised
|
|
2464
|
+
* mid-call can name it. A call pinned to an operation queues under its id
|
|
2465
|
+
* (`keystoneQueueKey`); a call without one queues under the wallet id or the
|
|
2466
|
+
* wallet connectId, and the live operation routed to that connection is still
|
|
2467
|
+
* the owner. Only a cold start comes back undefined.
|
|
2468
|
+
*/
|
|
2469
|
+
_activeOperationId() {
|
|
2470
|
+
const activeJobId = this._jobQueue.getActiveJob()?.deviceId;
|
|
2471
|
+
if (!activeJobId) return void 0;
|
|
2472
|
+
if ((0, import_hwk_adapter_core4.isHardwareOperationId)(activeJobId)) return activeJobId;
|
|
2473
|
+
return this._operationRouteForIdentifier(activeJobId)?.operationId;
|
|
2474
|
+
}
|
|
2475
|
+
/** Routes are keyed by connectId; a job key may be the bare wallet id. */
|
|
2476
|
+
_operationRouteForIdentifier(identifier) {
|
|
2477
|
+
for (const key of keystoneCancelQueueKeys([identifier])) {
|
|
2478
|
+
const route = this._operationRoutes.get(key);
|
|
2479
|
+
if (route) return route;
|
|
2480
|
+
}
|
|
2481
|
+
const walletId = keystoneWalletIdFromIdentifier(identifier);
|
|
2482
|
+
return walletId ? this._operationRoutes.get(walletConnectId(walletId)) : void 0;
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* A QR prompt has no transport to interrupt, so an aborted job would sit here
|
|
2486
|
+
* until the QR timeout. Releasing the registry slot on abort is what lets a
|
|
2487
|
+
* cancel reach the wait at all.
|
|
2488
|
+
*/
|
|
2489
|
+
async _awaitQrResponse(requestType, pending, signal) {
|
|
2490
|
+
if (!signal) return pending;
|
|
2491
|
+
let settled = false;
|
|
2492
|
+
const onAbort = () => {
|
|
2493
|
+
if (!settled) this._uiRegistry.cancel(requestType);
|
|
2494
|
+
};
|
|
2495
|
+
if (signal.aborted) onAbort();
|
|
2496
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
2497
|
+
try {
|
|
2498
|
+
return await pending;
|
|
2499
|
+
} finally {
|
|
2500
|
+
settled = true;
|
|
2501
|
+
signal.removeEventListener("abort", onAbort);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
async _requestQrDisplayAndAwaitResponse(device, data, signal) {
|
|
2505
|
+
const operationId = this._activeOperationId();
|
|
2388
2506
|
const waitPromise = this._uiRegistry.wait(
|
|
2389
|
-
|
|
2390
|
-
{ timeoutMs: this._qrTimeoutMs }
|
|
2507
|
+
import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2508
|
+
{ timeoutMs: this._qrTimeoutMs, operationId }
|
|
2391
2509
|
);
|
|
2392
|
-
this.emitter.emit(
|
|
2393
|
-
type:
|
|
2394
|
-
payload: { device, data }
|
|
2510
|
+
this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_DISPLAY, {
|
|
2511
|
+
type: import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2512
|
+
payload: { device, data, operationId }
|
|
2395
2513
|
});
|
|
2396
|
-
const response = await
|
|
2514
|
+
const response = await this._awaitQrResponse(
|
|
2515
|
+
import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2516
|
+
waitPromise,
|
|
2517
|
+
signal
|
|
2518
|
+
);
|
|
2397
2519
|
return { urType: response.urType, urData: response.urData };
|
|
2398
2520
|
}
|
|
2399
|
-
async _requestQrScanAndAwaitResponse(device) {
|
|
2521
|
+
async _requestQrScanAndAwaitResponse(device, signal) {
|
|
2522
|
+
const operationId = this._activeOperationId();
|
|
2400
2523
|
const waitPromise = this._uiRegistry.wait(
|
|
2401
|
-
|
|
2402
|
-
{ timeoutMs: this._qrTimeoutMs }
|
|
2524
|
+
import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_SCAN,
|
|
2525
|
+
{ timeoutMs: this._qrTimeoutMs, operationId }
|
|
2403
2526
|
);
|
|
2404
|
-
this.emitter.emit(
|
|
2405
|
-
type:
|
|
2406
|
-
payload: { device }
|
|
2527
|
+
this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_SCAN, {
|
|
2528
|
+
type: import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_SCAN,
|
|
2529
|
+
payload: { device, operationId }
|
|
2407
2530
|
});
|
|
2408
|
-
const response = await waitPromise;
|
|
2531
|
+
const response = await this._awaitQrResponse(import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_SCAN, waitPromise, signal);
|
|
2409
2532
|
return { urType: response.urType, urData: response.urData };
|
|
2410
2533
|
}
|
|
2411
2534
|
async _callUsbConnector(sessionId, method, params, signal) {
|
|
2412
2535
|
if (!this._usbConnector) {
|
|
2413
|
-
throw (0,
|
|
2414
|
-
code:
|
|
2536
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2537
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
2415
2538
|
message: "No USB connector configured for this Keystone adapter"
|
|
2416
2539
|
});
|
|
2417
2540
|
}
|
|
2418
2541
|
if (this._pendingUsbTeardowns > 0 || this._unsettledUsbOperations.size > 0) {
|
|
2419
|
-
throw (0,
|
|
2420
|
-
code:
|
|
2542
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2543
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceBusyInternal,
|
|
2421
2544
|
message: `Keystone USB is busy while calling ${method}`
|
|
2422
2545
|
});
|
|
2423
2546
|
}
|
|
2547
|
+
if (signal?.aborted) {
|
|
2548
|
+
throw signal.reason instanceof Error ? signal.reason : (0, import_hwk_adapter_core4.createHwkError)({
|
|
2549
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.UserAborted,
|
|
2550
|
+
message: "User aborted operation"
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2424
2553
|
const releaseOperation = this._retainUsbOperation(`call:${sessionId}`);
|
|
2425
2554
|
let rawCall;
|
|
2426
2555
|
try {
|
|
@@ -2502,16 +2631,16 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2502
2631
|
}
|
|
2503
2632
|
static _assertRequestIdMatches(expected, actual) {
|
|
2504
2633
|
if (actual && actual.toLowerCase() !== expected.toLowerCase()) {
|
|
2505
|
-
throw (0,
|
|
2506
|
-
code:
|
|
2634
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2635
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2507
2636
|
message: "Keystone response requestId does not match the pending request \u2014 discarding a stale or unrelated scan"
|
|
2508
2637
|
});
|
|
2509
2638
|
}
|
|
2510
2639
|
}
|
|
2511
2640
|
_unsupported(method, reason) {
|
|
2512
2641
|
return Promise.resolve(
|
|
2513
|
-
(0,
|
|
2514
|
-
|
|
2642
|
+
(0, import_hwk_adapter_core4.failure)(
|
|
2643
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
2515
2644
|
`KeystoneAdapter.${method} is not implemented yet: ${reason}`
|
|
2516
2645
|
)
|
|
2517
2646
|
);
|
|
@@ -2519,32 +2648,32 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2519
2648
|
_errorToFailure(err) {
|
|
2520
2649
|
if (err && typeof err === "object") {
|
|
2521
2650
|
const e = err;
|
|
2522
|
-
if (typeof e.code === "number") {
|
|
2651
|
+
if (typeof e.code === "number" && e.code >= 1e4 && e.code <= 99999) {
|
|
2523
2652
|
const { origin } = e;
|
|
2524
|
-
return (0,
|
|
2653
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2525
2654
|
e.code,
|
|
2526
2655
|
e.message ?? "Unknown error",
|
|
2527
2656
|
e.params,
|
|
2528
2657
|
origin === "device" || origin === "transport" || origin === "host" ? origin : void 0,
|
|
2529
|
-
(0,
|
|
2658
|
+
(0, import_hwk_adapter_core4.isHwkRecoveryHint)(e.recovery) ? e.recovery : void 0
|
|
2530
2659
|
);
|
|
2531
2660
|
}
|
|
2532
|
-
if (e._tag ===
|
|
2533
|
-
return (0,
|
|
2534
|
-
|
|
2661
|
+
if (e._tag === import_hwk_adapter_core4.UI_REQUEST_CANCELLED_TAG || e._tag === import_hwk_adapter_core4.UI_REQUEST_PREEMPTED_TAG) {
|
|
2662
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2663
|
+
import_hwk_adapter_core4.HardwareErrorCode.UserAborted,
|
|
2535
2664
|
e.message ?? "Keystone QR operation was cancelled"
|
|
2536
2665
|
);
|
|
2537
2666
|
}
|
|
2538
|
-
if (e._tag ===
|
|
2539
|
-
return (0,
|
|
2540
|
-
|
|
2667
|
+
if (e._tag === import_hwk_adapter_core4.UI_REQUEST_TIMEOUT_TAG) {
|
|
2668
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2669
|
+
import_hwk_adapter_core4.HardwareErrorCode.OperationTimeout,
|
|
2541
2670
|
e.message ?? "Keystone QR operation timed out"
|
|
2542
2671
|
);
|
|
2543
2672
|
}
|
|
2544
2673
|
}
|
|
2545
2674
|
const message = err instanceof Error ? err.message : String(err);
|
|
2546
2675
|
const params = err instanceof Error && err.stack ? { stack: err.stack } : void 0;
|
|
2547
|
-
return (0,
|
|
2676
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.UnknownError, message, params);
|
|
2548
2677
|
}
|
|
2549
2678
|
};
|
|
2550
2679
|
// Annotate the CommonJS export names for ESM import in node:
|