@onekeyfe/hwk-keystone-adapter 1.2.3-alpha.4 → 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 +394 -271
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -69
- 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,19 +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,
|
|
1465
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params.psbt");
|
|
1404
1466
|
if (!params.path)
|
|
1405
|
-
return (0,
|
|
1467
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignPsbt requires params.path");
|
|
1406
1468
|
if (!isKeystoneSignableBtcAccountPath(splitAccountPath(params.path).accountPath)) {
|
|
1407
|
-
return (0,
|
|
1469
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1408
1470
|
}
|
|
1409
1471
|
try {
|
|
1410
|
-
return await this._jobQueue.enqueue(
|
|
1472
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1411
1473
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1412
1474
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1413
|
-
const requestUr = this.urEngine.buildBtcPsbtRequest((0,
|
|
1475
|
+
const requestUr = this.urEngine.buildBtcPsbtRequest((0, import_hwk_adapter_core4.stripHex)(params.psbt));
|
|
1414
1476
|
const responseUr = await this._resolveUr(
|
|
1415
1477
|
record,
|
|
1416
1478
|
requestUr,
|
|
@@ -1421,7 +1483,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1421
1483
|
);
|
|
1422
1484
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1423
1485
|
const signedPsbt = this.urEngine.parseBtcPsbt(responseUr);
|
|
1424
|
-
return (0,
|
|
1486
|
+
return (0, import_hwk_adapter_core4.success)({ signedPsbt });
|
|
1425
1487
|
});
|
|
1426
1488
|
} catch (err) {
|
|
1427
1489
|
return this._errorToFailure(err);
|
|
@@ -1433,27 +1495,28 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1433
1495
|
const connectId = operationTarget.payload.targetId;
|
|
1434
1496
|
const deviceId = deviceIdArg ?? void 0;
|
|
1435
1497
|
const params = paramsArg;
|
|
1436
|
-
if (!params) return (0,
|
|
1498
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "btcSignMessage requires params");
|
|
1437
1499
|
if (!params.path || params.message === void 0) {
|
|
1438
|
-
return (0,
|
|
1439
|
-
|
|
1500
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1501
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1440
1502
|
"btcSignMessage requires params.path and params.message"
|
|
1441
1503
|
);
|
|
1442
1504
|
}
|
|
1443
|
-
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");
|
|
1444
1506
|
const path = normalizePath(params.path);
|
|
1445
1507
|
if (!isKeystoneSignableBtcAccountPath(splitAccountPath(path).accountPath)) {
|
|
1446
|
-
return (0,
|
|
1508
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.DevicePathForbidden, KEYSTONE_BTC_ACCOUNT_FORBIDDEN_MESSAGE);
|
|
1447
1509
|
}
|
|
1448
1510
|
try {
|
|
1449
|
-
return await this._jobQueue.enqueue(
|
|
1511
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1450
1512
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1451
1513
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1452
1514
|
const requestId = (0, import_uuid2.v4)();
|
|
1453
1515
|
const requestUr = this.urEngine.buildBtcMessageSignRequest({
|
|
1454
1516
|
requestId,
|
|
1455
1517
|
messageHex,
|
|
1456
|
-
accounts: [{ path, xfp: record.masterFingerprint }]
|
|
1518
|
+
accounts: [{ path, xfp: record.masterFingerprint }],
|
|
1519
|
+
origin: this._origin
|
|
1457
1520
|
});
|
|
1458
1521
|
const responseUr = await this._resolveUr(
|
|
1459
1522
|
record,
|
|
@@ -1466,7 +1529,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1466
1529
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1467
1530
|
const sig = this.urEngine.parseBtcSignature(responseUr);
|
|
1468
1531
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1469
|
-
return (0,
|
|
1532
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1470
1533
|
});
|
|
1471
1534
|
} catch (err) {
|
|
1472
1535
|
return this._errorToFailure(err);
|
|
@@ -1478,9 +1541,9 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1478
1541
|
const connectId = operationTarget.payload.targetId;
|
|
1479
1542
|
const deviceId = deviceIdArg ?? void 0;
|
|
1480
1543
|
try {
|
|
1481
|
-
return await this._jobQueue.enqueue(
|
|
1544
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1482
1545
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "btc", signal);
|
|
1483
|
-
return (0,
|
|
1546
|
+
return (0, import_hwk_adapter_core4.success)({ masterFingerprint: record.masterFingerprint });
|
|
1484
1547
|
});
|
|
1485
1548
|
} catch (err) {
|
|
1486
1549
|
return this._errorToFailure(err);
|
|
@@ -1495,18 +1558,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1495
1558
|
const connectId = operationTarget.payload.targetId;
|
|
1496
1559
|
const deviceId = deviceIdArg ?? void 0;
|
|
1497
1560
|
const params = paramsArg;
|
|
1498
|
-
if (!params) return (0,
|
|
1561
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solGetAddress requires params");
|
|
1499
1562
|
if (!params.path)
|
|
1500
|
-
return (0,
|
|
1563
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solGetAddress requires params.path");
|
|
1501
1564
|
const path = normalizePath(params.path);
|
|
1502
1565
|
try {
|
|
1503
|
-
return await this._jobQueue.enqueue(
|
|
1566
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1504
1567
|
const { account } = await this._fetchAccount(connectId, deviceId, "sol", path, signal, {
|
|
1505
1568
|
book
|
|
1506
1569
|
});
|
|
1507
1570
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1508
1571
|
const address = import_bs58.default.encode(Buffer.from(account.publicKey, "hex"));
|
|
1509
|
-
return (0,
|
|
1572
|
+
return (0, import_hwk_adapter_core4.success)({ address, path });
|
|
1510
1573
|
});
|
|
1511
1574
|
} catch (err) {
|
|
1512
1575
|
return this._errorToFailure(err);
|
|
@@ -1519,25 +1582,26 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1519
1582
|
const deviceId = deviceIdArg ?? void 0;
|
|
1520
1583
|
const params = paramsArg;
|
|
1521
1584
|
if (!params)
|
|
1522
|
-
return (0,
|
|
1585
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solSignTransaction requires params");
|
|
1523
1586
|
if (!params.path || !params.serializedTx) {
|
|
1524
|
-
return (0,
|
|
1525
|
-
|
|
1587
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1588
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1526
1589
|
"solSignTransaction requires params.path and params.serializedTx"
|
|
1527
1590
|
);
|
|
1528
1591
|
}
|
|
1529
1592
|
const path = normalizePath(params.path);
|
|
1530
1593
|
try {
|
|
1531
|
-
return await this._jobQueue.enqueue(
|
|
1594
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1532
1595
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "sol", signal);
|
|
1533
1596
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1534
1597
|
const requestId = (0, import_uuid2.v4)();
|
|
1535
1598
|
const requestUr = this.urEngine.buildSolSignRequest({
|
|
1536
1599
|
requestId,
|
|
1537
|
-
unsignedPayloadHex: (0,
|
|
1600
|
+
unsignedPayloadHex: (0, import_hwk_adapter_core4.stripHex)(params.serializedTx),
|
|
1538
1601
|
dataType: "transaction",
|
|
1539
1602
|
path,
|
|
1540
|
-
xfp: record.masterFingerprint
|
|
1603
|
+
xfp: record.masterFingerprint,
|
|
1604
|
+
origin: this._origin
|
|
1541
1605
|
});
|
|
1542
1606
|
const responseUr = await this._resolveUr(
|
|
1543
1607
|
record,
|
|
@@ -1550,7 +1614,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1550
1614
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1551
1615
|
const sig = this.urEngine.parseSolSignature(responseUr);
|
|
1552
1616
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1553
|
-
return (0,
|
|
1617
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1554
1618
|
});
|
|
1555
1619
|
} catch (err) {
|
|
1556
1620
|
return this._errorToFailure(err);
|
|
@@ -1562,25 +1626,26 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1562
1626
|
const connectId = operationTarget.payload.targetId;
|
|
1563
1627
|
const deviceId = deviceIdArg ?? void 0;
|
|
1564
1628
|
const params = paramsArg;
|
|
1565
|
-
if (!params) return (0,
|
|
1629
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "solSignMessage requires params");
|
|
1566
1630
|
if (!params.path || !params.message) {
|
|
1567
|
-
return (0,
|
|
1568
|
-
|
|
1631
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1632
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1569
1633
|
"solSignMessage requires params.path and params.message"
|
|
1570
1634
|
);
|
|
1571
1635
|
}
|
|
1572
1636
|
const path = normalizePath(params.path);
|
|
1573
1637
|
try {
|
|
1574
|
-
return await this._jobQueue.enqueue(
|
|
1638
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1575
1639
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "sol", signal);
|
|
1576
1640
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1577
1641
|
const requestId = (0, import_uuid2.v4)();
|
|
1578
1642
|
const requestUr = this.urEngine.buildSolSignRequest({
|
|
1579
1643
|
requestId,
|
|
1580
|
-
unsignedPayloadHex: (0,
|
|
1644
|
+
unsignedPayloadHex: (0, import_hwk_adapter_core4.stripHex)(params.message),
|
|
1581
1645
|
dataType: "message",
|
|
1582
1646
|
path,
|
|
1583
|
-
xfp: record.masterFingerprint
|
|
1647
|
+
xfp: record.masterFingerprint,
|
|
1648
|
+
origin: this._origin
|
|
1584
1649
|
});
|
|
1585
1650
|
const responseUr = await this._resolveUr(
|
|
1586
1651
|
record,
|
|
@@ -1593,7 +1658,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1593
1658
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1594
1659
|
const sig = this.urEngine.parseSolSignature(responseUr);
|
|
1595
1660
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1596
|
-
return (0,
|
|
1661
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1597
1662
|
});
|
|
1598
1663
|
} catch (err) {
|
|
1599
1664
|
return this._errorToFailure(err);
|
|
@@ -1613,18 +1678,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1613
1678
|
const connectId = operationTarget.payload.targetId;
|
|
1614
1679
|
const deviceId = deviceIdArg ?? void 0;
|
|
1615
1680
|
const params = paramsArg;
|
|
1616
|
-
if (!params) return (0,
|
|
1681
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronGetAddress requires params");
|
|
1617
1682
|
if (!params.path)
|
|
1618
|
-
return (0,
|
|
1683
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronGetAddress requires params.path");
|
|
1619
1684
|
const { accountPath, relativeDerivePath } = splitAccountPath(params.path);
|
|
1620
1685
|
if (!relativeDerivePath) {
|
|
1621
|
-
return (0,
|
|
1622
|
-
|
|
1686
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1687
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1623
1688
|
"tronGetAddress requires a full leaf path, e.g. m/44'/195'/0'/0/0"
|
|
1624
1689
|
);
|
|
1625
1690
|
}
|
|
1626
1691
|
try {
|
|
1627
|
-
return await this._jobQueue.enqueue(
|
|
1692
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1628
1693
|
const { account } = await this._fetchAccount(
|
|
1629
1694
|
connectId,
|
|
1630
1695
|
deviceId,
|
|
@@ -1635,8 +1700,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1635
1700
|
);
|
|
1636
1701
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1637
1702
|
if (!account.extendedPublicKey) {
|
|
1638
|
-
throw (0,
|
|
1639
|
-
code:
|
|
1703
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1704
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1640
1705
|
message: "Keystone did not return an extended public key for this account path"
|
|
1641
1706
|
});
|
|
1642
1707
|
}
|
|
@@ -1644,7 +1709,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1644
1709
|
account.extendedPublicKey,
|
|
1645
1710
|
relativeDerivePath
|
|
1646
1711
|
);
|
|
1647
|
-
return (0,
|
|
1712
|
+
return (0, import_hwk_adapter_core4.success)({ address, path: normalizePath(params.path) });
|
|
1648
1713
|
});
|
|
1649
1714
|
} catch (err) {
|
|
1650
1715
|
return this._errorToFailure(err);
|
|
@@ -1657,20 +1722,20 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1657
1722
|
const deviceId = deviceIdArg ?? void 0;
|
|
1658
1723
|
const params = paramsArg;
|
|
1659
1724
|
if (!params)
|
|
1660
|
-
return (0,
|
|
1725
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignTransaction requires params");
|
|
1661
1726
|
if (!params.path) {
|
|
1662
|
-
return (0,
|
|
1727
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignTransaction requires params.path");
|
|
1663
1728
|
}
|
|
1664
1729
|
if (!params.rawTxHex) {
|
|
1665
|
-
return (0,
|
|
1666
|
-
|
|
1730
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1731
|
+
import_hwk_adapter_core4.HardwareErrorCode.InvalidParams,
|
|
1667
1732
|
"Keystone only signs a fully protobuf-serialized TRON transaction (params.rawTxHex) \u2014 the Trezor-style structured contract fields have no equivalent here"
|
|
1668
1733
|
);
|
|
1669
1734
|
}
|
|
1670
|
-
const rawTxHex = (0,
|
|
1735
|
+
const rawTxHex = (0, import_hwk_adapter_core4.stripHex)(params.rawTxHex);
|
|
1671
1736
|
const path = normalizePath(params.path);
|
|
1672
1737
|
try {
|
|
1673
|
-
return await this._jobQueue.enqueue(
|
|
1738
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1674
1739
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "tron", signal);
|
|
1675
1740
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1676
1741
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1678,7 +1743,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1678
1743
|
requestId,
|
|
1679
1744
|
rawTxHex,
|
|
1680
1745
|
path,
|
|
1681
|
-
xfp: record.masterFingerprint
|
|
1746
|
+
xfp: record.masterFingerprint,
|
|
1747
|
+
origin: this._origin
|
|
1682
1748
|
});
|
|
1683
1749
|
const responseUr = await this._resolveUr(
|
|
1684
1750
|
record,
|
|
@@ -1691,7 +1757,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1691
1757
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1692
1758
|
const sig = this.urEngine.parseTronSignature(responseUr);
|
|
1693
1759
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1694
|
-
return (0,
|
|
1760
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1695
1761
|
});
|
|
1696
1762
|
} catch (err) {
|
|
1697
1763
|
return this._errorToFailure(err);
|
|
@@ -1703,23 +1769,23 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1703
1769
|
const connectId = operationTarget.payload.targetId;
|
|
1704
1770
|
const deviceId = deviceIdArg ?? void 0;
|
|
1705
1771
|
const params = paramsArg;
|
|
1706
|
-
if (!params) return (0,
|
|
1772
|
+
if (!params) return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignMessage requires params");
|
|
1707
1773
|
if (!params.path) {
|
|
1708
|
-
return (0,
|
|
1774
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignMessage requires params.path");
|
|
1709
1775
|
}
|
|
1710
1776
|
if (!params.messageHex) {
|
|
1711
|
-
return (0,
|
|
1777
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.InvalidParams, "tronSignMessage requires params.messageHex");
|
|
1712
1778
|
}
|
|
1713
1779
|
if (params.messageType !== "V2") {
|
|
1714
|
-
return (0,
|
|
1715
|
-
|
|
1780
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
1781
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
1716
1782
|
'Keystone signs TRON messages as TIP-191 signMessageV2 only (messageType: "V2")'
|
|
1717
1783
|
);
|
|
1718
1784
|
}
|
|
1719
|
-
const messageHex = (0,
|
|
1785
|
+
const messageHex = (0, import_hwk_adapter_core4.stripHex)(params.messageHex);
|
|
1720
1786
|
const path = normalizePath(params.path);
|
|
1721
1787
|
try {
|
|
1722
|
-
return await this._jobQueue.enqueue(
|
|
1788
|
+
return await this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1723
1789
|
const { record } = await this._ensureWalletKnown(connectId, deviceId, "tron", signal);
|
|
1724
1790
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1725
1791
|
const requestId = (0, import_uuid2.v4)();
|
|
@@ -1728,7 +1794,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1728
1794
|
rawTxHex: messageHex,
|
|
1729
1795
|
path,
|
|
1730
1796
|
xfp: record.masterFingerprint,
|
|
1731
|
-
signType: 2 /* PersonalMessage
|
|
1797
|
+
signType: 2 /* PersonalMessage */,
|
|
1798
|
+
origin: this._origin
|
|
1732
1799
|
});
|
|
1733
1800
|
const responseUr = await this._resolveUr(
|
|
1734
1801
|
record,
|
|
@@ -1741,7 +1808,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1741
1808
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1742
1809
|
const sig = this.urEngine.parseTronSignature(responseUr);
|
|
1743
1810
|
_KeystoneAdapter._assertRequestIdMatches(requestId, sig.requestId);
|
|
1744
|
-
return (0,
|
|
1811
|
+
return (0, import_hwk_adapter_core4.success)({ signature: sig.signature });
|
|
1745
1812
|
});
|
|
1746
1813
|
} catch (err) {
|
|
1747
1814
|
return this._errorToFailure(err);
|
|
@@ -1751,13 +1818,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1751
1818
|
// Internals
|
|
1752
1819
|
// ---------------------------------------------------------------------------
|
|
1753
1820
|
_walletIdFromIdentifier(identifier) {
|
|
1754
|
-
|
|
1755
|
-
return /^[0-9a-f]{64}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
1821
|
+
return keystoneWalletIdFromIdentifier(identifier);
|
|
1756
1822
|
}
|
|
1757
1823
|
_allNetworkSyncSchema(item) {
|
|
1758
|
-
if (!(0,
|
|
1824
|
+
if (!(0, import_hwk_adapter_core4.isAllNetworkMethodName)(String(item.methodName)) || !item.path) return void 0;
|
|
1759
1825
|
const method = item.methodName;
|
|
1760
|
-
const hwkChain = (0,
|
|
1826
|
+
const hwkChain = (0, import_hwk_adapter_core4.getAllNetworkMethodChain)(method);
|
|
1761
1827
|
const path = normalizePath(item.path);
|
|
1762
1828
|
if (hwkChain === "btc" && !isKeystoneSignableBtcAccountPath(splitAccountPath(path).accountPath)) {
|
|
1763
1829
|
return void 0;
|
|
@@ -1781,7 +1847,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1781
1847
|
* one-path-at-a-time export flow because the device limits that channel.
|
|
1782
1848
|
*/
|
|
1783
1849
|
async _prefetchAllNetworkAccounts(connectId, deviceId, params) {
|
|
1784
|
-
return this._jobQueue.enqueue(
|
|
1850
|
+
return this._jobQueue.enqueue(keystoneQueueKey(connectId, deviceId), async (signal) => {
|
|
1785
1851
|
const target = this._resolveTarget(connectId, deviceId);
|
|
1786
1852
|
const { record: targetRecord } = target;
|
|
1787
1853
|
let record = targetRecord;
|
|
@@ -1794,7 +1860,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1794
1860
|
if (!requestedByKey.size) {
|
|
1795
1861
|
return { book };
|
|
1796
1862
|
}
|
|
1797
|
-
const operation = (0,
|
|
1863
|
+
const operation = (0, import_hwk_adapter_core4.isHardwareOperationId)(params.operationId) ? this._operations.find(params.operationId) : void 0;
|
|
1798
1864
|
const operationRoute = operation ? this._operationRoutes.get(operation.connectId) : void 0;
|
|
1799
1865
|
const routedToQr = operationRoute?.operationId === operation?.operationId && operationRoute?.connectionType === "qr";
|
|
1800
1866
|
if (this._forcedTransport !== "qr" && !routedToQr && !record?.usbSessionId && this._usbConnector && target.expectedWalletId) {
|
|
@@ -1808,8 +1874,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1808
1874
|
const bundleSessionId = record.usbSessionId;
|
|
1809
1875
|
const assertBundleSession = () => {
|
|
1810
1876
|
if (record?.usbSessionId !== bundleSessionId) {
|
|
1811
|
-
throw (0,
|
|
1812
|
-
code:
|
|
1877
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1878
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
1813
1879
|
message: "Keystone USB connection was lost during account export"
|
|
1814
1880
|
});
|
|
1815
1881
|
}
|
|
@@ -1832,8 +1898,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1832
1898
|
}
|
|
1833
1899
|
for (const schema of missingSchemas2) {
|
|
1834
1900
|
if (!book.has(accountKey(schema.hwkChain, schema.path))) {
|
|
1835
|
-
throw (0,
|
|
1836
|
-
code:
|
|
1901
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1902
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1837
1903
|
message: `Keystone did not return the requested derivation path (${schema.path})`
|
|
1838
1904
|
});
|
|
1839
1905
|
}
|
|
@@ -1841,8 +1907,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1841
1907
|
return { book, walletId: record.walletId };
|
|
1842
1908
|
}
|
|
1843
1909
|
if (this._forcedTransport === "usb") {
|
|
1844
|
-
throw (0,
|
|
1845
|
-
code:
|
|
1910
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1911
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
1846
1912
|
message: "USB channel is not connected for this Keystone wallet"
|
|
1847
1913
|
});
|
|
1848
1914
|
}
|
|
@@ -1860,7 +1926,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1860
1926
|
});
|
|
1861
1927
|
const responseUr = await this._requestQrDisplayAndAwaitResponse(
|
|
1862
1928
|
record ? toDeviceInfo(record) : placeholderDeviceInfo(),
|
|
1863
|
-
{ ...requestUr, animated: false }
|
|
1929
|
+
{ ...requestUr, animated: false },
|
|
1930
|
+
signal
|
|
1864
1931
|
);
|
|
1865
1932
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
1866
1933
|
const parsed = this.urEngine.parseAccountResponse(responseUr);
|
|
@@ -1881,8 +1948,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1881
1948
|
}
|
|
1882
1949
|
for (const schema of missingSchemas) {
|
|
1883
1950
|
if (!book.has(accountKey(schema.hwkChain, schema.path))) {
|
|
1884
|
-
throw (0,
|
|
1885
|
-
code:
|
|
1951
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1952
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1886
1953
|
message: `Keystone did not return the requested derivation path (${schema.path})`
|
|
1887
1954
|
});
|
|
1888
1955
|
}
|
|
@@ -1896,7 +1963,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1896
1963
|
*/
|
|
1897
1964
|
_resolveTarget(connectId, deviceId) {
|
|
1898
1965
|
let resolvedConnectId = connectId;
|
|
1899
|
-
if ((0,
|
|
1966
|
+
if ((0, import_hwk_adapter_core4.isHardwareOperationId)(connectId)) {
|
|
1900
1967
|
resolvedConnectId = this._operations.resolve(connectId).connectId;
|
|
1901
1968
|
}
|
|
1902
1969
|
const identifiers = [deviceId, resolvedConnectId].filter(
|
|
@@ -1905,21 +1972,21 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1905
1972
|
if (!identifiers.length) return {};
|
|
1906
1973
|
const walletIds = identifiers.map((identifier) => this._walletIdFromIdentifier(identifier)).filter((walletId) => Boolean(walletId));
|
|
1907
1974
|
if (!walletIds.length) {
|
|
1908
|
-
throw (0,
|
|
1909
|
-
code:
|
|
1975
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1976
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceNotFound,
|
|
1910
1977
|
message: "Keystone device lookup requires a 64-hex wallet identity"
|
|
1911
1978
|
});
|
|
1912
1979
|
}
|
|
1913
1980
|
const expectedWalletId = walletIds[0];
|
|
1914
1981
|
if (walletIds.some((walletId) => walletId !== expectedWalletId)) {
|
|
1915
|
-
throw (0,
|
|
1916
|
-
code:
|
|
1982
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1983
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1917
1984
|
message: "Keystone connectId and deviceId identify different wallets"
|
|
1918
1985
|
});
|
|
1919
1986
|
}
|
|
1920
1987
|
if (identifiers.some((identifier) => !this._walletIdFromIdentifier(identifier))) {
|
|
1921
|
-
throw (0,
|
|
1922
|
-
code:
|
|
1988
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
1989
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1923
1990
|
message: "Keystone connectId and deviceId are inconsistent"
|
|
1924
1991
|
});
|
|
1925
1992
|
}
|
|
@@ -1933,14 +2000,14 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1933
2000
|
_assertParsedIdentity(parsed, expected) {
|
|
1934
2001
|
const walletId = deriveKeystoneWalletId(parsed.accounts);
|
|
1935
2002
|
if (expected.expectedMasterFingerprint && parsed.masterFingerprint !== expected.expectedMasterFingerprint) {
|
|
1936
|
-
throw (0,
|
|
1937
|
-
code:
|
|
2003
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2004
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1938
2005
|
message: `Connected Keystone wallet (mfp ${parsed.masterFingerprint}) does not match the requested wallet fingerprint (${expected.expectedMasterFingerprint})`
|
|
1939
2006
|
});
|
|
1940
2007
|
}
|
|
1941
2008
|
if (expected.expectedWalletId && walletId !== expected.expectedWalletId) {
|
|
1942
|
-
throw (0,
|
|
1943
|
-
code:
|
|
2009
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2010
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1944
2011
|
message: "Connected Keystone wallet does not match the requested wallet identity"
|
|
1945
2012
|
});
|
|
1946
2013
|
}
|
|
@@ -1963,8 +2030,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1963
2030
|
record = createDeviceRecord(walletId, parsed.masterFingerprint);
|
|
1964
2031
|
this._devices.set(walletId, record);
|
|
1965
2032
|
} else if (record.masterFingerprint !== parsed.masterFingerprint) {
|
|
1966
|
-
throw (0,
|
|
1967
|
-
code:
|
|
2033
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2034
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
1968
2035
|
message: "Keystone wallet identity returned an inconsistent master fingerprint"
|
|
1969
2036
|
});
|
|
1970
2037
|
}
|
|
@@ -1974,7 +2041,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1974
2041
|
record.usbSessionId = options?.usbSessionId ?? record.usbSessionId;
|
|
1975
2042
|
if (!options?.viaUsb) record.qrSynced = true;
|
|
1976
2043
|
const info = toDeviceInfo(record);
|
|
1977
|
-
const eventType = isNew ?
|
|
2044
|
+
const eventType = isNew ? import_hwk_adapter_core4.DEVICE.CONNECT : import_hwk_adapter_core4.DEVICE.CHANGED;
|
|
1978
2045
|
this.emitter.emit(eventType, { type: eventType, payload: info });
|
|
1979
2046
|
return record;
|
|
1980
2047
|
}
|
|
@@ -1989,8 +2056,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
1989
2056
|
*/
|
|
1990
2057
|
async _connectUsb(expected, searchTargetId) {
|
|
1991
2058
|
if (this._pendingUsbTeardowns > 0) {
|
|
1992
|
-
return (0,
|
|
1993
|
-
|
|
2059
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2060
|
+
import_hwk_adapter_core4.HardwareErrorCode.DeviceBusyInternal,
|
|
1994
2061
|
"Keystone USB session is being released"
|
|
1995
2062
|
);
|
|
1996
2063
|
}
|
|
@@ -2008,8 +2075,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2008
2075
|
}
|
|
2009
2076
|
async _connectUsbExclusive(expected, searchTargetId) {
|
|
2010
2077
|
if (!this._usbConnector) {
|
|
2011
|
-
return (0,
|
|
2012
|
-
|
|
2078
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2079
|
+
import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
2013
2080
|
"No USB connector configured for this Keystone adapter"
|
|
2014
2081
|
);
|
|
2015
2082
|
}
|
|
@@ -2028,17 +2095,17 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2028
2095
|
const session = await (connector.connectTarget ? connector.connectTarget(connectTarget) : connector.connect(searchTargetId ?? expected.expectedMasterFingerprint));
|
|
2029
2096
|
sessionId = session.sessionId;
|
|
2030
2097
|
const raw = session.deviceInfo.raw;
|
|
2031
|
-
const mfpValue = (0,
|
|
2098
|
+
const mfpValue = (0, import_hwk_adapter_core4.parseBip32MasterFingerprint)(raw?.masterFingerprint);
|
|
2032
2099
|
if (!mfpValue) {
|
|
2033
|
-
throw (0,
|
|
2034
|
-
code:
|
|
2100
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2101
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2035
2102
|
message: "Keystone USB did not report a master fingerprint"
|
|
2036
2103
|
});
|
|
2037
2104
|
}
|
|
2038
2105
|
const masterFingerprint = mfpValue.toLowerCase();
|
|
2039
2106
|
if (expected.expectedMasterFingerprint && masterFingerprint !== expected.expectedMasterFingerprint) {
|
|
2040
|
-
throw (0,
|
|
2041
|
-
code:
|
|
2107
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2108
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2042
2109
|
message: `Connected Keystone wallet (mfp ${masterFingerprint}) does not match the requested wallet fingerprint (${expected.expectedMasterFingerprint})`
|
|
2043
2110
|
});
|
|
2044
2111
|
}
|
|
@@ -2052,7 +2119,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2052
2119
|
identityRequest
|
|
2053
2120
|
);
|
|
2054
2121
|
if (!identityResult.success) {
|
|
2055
|
-
throw (0,
|
|
2122
|
+
throw (0, import_hwk_adapter_core4.rehydrateConnectorError)(identityResult.error);
|
|
2056
2123
|
}
|
|
2057
2124
|
const parsed = this.urEngine.parseAccountResponse(identityResult.payload);
|
|
2058
2125
|
this._assertParsedIdentity(parsed, {
|
|
@@ -2075,7 +2142,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2075
2142
|
record.model = session.deviceInfo.modelName ?? session.deviceInfo.model ?? record.model;
|
|
2076
2143
|
record.deviceVersion = session.deviceInfo.firmwareVersion ?? record.deviceVersion;
|
|
2077
2144
|
const info = toDeviceInfo(record);
|
|
2078
|
-
return (0,
|
|
2145
|
+
return (0, import_hwk_adapter_core4.success)(info);
|
|
2079
2146
|
} catch (err) {
|
|
2080
2147
|
if (sessionId) {
|
|
2081
2148
|
try {
|
|
@@ -2146,7 +2213,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2146
2213
|
* closed rather than silently falling back to QR.
|
|
2147
2214
|
*/
|
|
2148
2215
|
async _resolveUr(record, requestUr, animated, operationId, signal, operationName) {
|
|
2149
|
-
const releaseOperationRetention = (0,
|
|
2216
|
+
const releaseOperationRetention = (0, import_hwk_adapter_core4.isHardwareOperationId)(operationId) ? this._operations.retain(operationId) : void 0;
|
|
2150
2217
|
try {
|
|
2151
2218
|
return await this._resolveUrWithRoute(
|
|
2152
2219
|
record,
|
|
@@ -2162,13 +2229,13 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2162
2229
|
}
|
|
2163
2230
|
async _resolveUrWithRoute(record, requestUr, animated, operationId, signal, operationName) {
|
|
2164
2231
|
let interactionRoute;
|
|
2165
|
-
if ((0,
|
|
2232
|
+
if ((0, import_hwk_adapter_core4.isHardwareOperationId)(operationId)) {
|
|
2166
2233
|
const operation = this._operations.resolve(operationId);
|
|
2167
2234
|
const route = this._operationRoutes.get(operation.connectId);
|
|
2168
2235
|
if (!route || route.operationId !== operationId) {
|
|
2169
2236
|
this._operations.end(operationId, "disconnect");
|
|
2170
|
-
throw (0,
|
|
2171
|
-
code:
|
|
2237
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2238
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationEnded,
|
|
2172
2239
|
message: "Keystone hardware operation is no longer connected",
|
|
2173
2240
|
params: { operationId, reason: "disconnect" }
|
|
2174
2241
|
});
|
|
@@ -2185,8 +2252,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2185
2252
|
if (!record?.usbSessionId || !this._usbConnector) {
|
|
2186
2253
|
if (interactionRoute) {
|
|
2187
2254
|
this._operations.end(interactionRoute.operationId, "disconnect");
|
|
2188
|
-
throw (0,
|
|
2189
|
-
code:
|
|
2255
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2256
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationEnded,
|
|
2190
2257
|
message: "Keystone operation USB connection was lost",
|
|
2191
2258
|
params: {
|
|
2192
2259
|
operationId: interactionRoute.operationId,
|
|
@@ -2194,8 +2261,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2194
2261
|
}
|
|
2195
2262
|
});
|
|
2196
2263
|
}
|
|
2197
|
-
throw (0,
|
|
2198
|
-
code:
|
|
2264
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2265
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
2199
2266
|
message: "USB channel is not connected for this Keystone wallet"
|
|
2200
2267
|
});
|
|
2201
2268
|
}
|
|
@@ -2206,17 +2273,18 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2206
2273
|
signal
|
|
2207
2274
|
);
|
|
2208
2275
|
if (result.success) return result.payload;
|
|
2209
|
-
const usbError = (0,
|
|
2276
|
+
const usbError = (0, import_hwk_adapter_core4.rehydrateConnectorError)(result.error);
|
|
2210
2277
|
const usbErrorOrigin = usbError.origin;
|
|
2211
2278
|
const usbErrorCode = usbError.code;
|
|
2212
|
-
if (!interactionRoute && !this._forcedTransport && usbErrorCode ===
|
|
2279
|
+
if (!interactionRoute && !this._forcedTransport && usbErrorCode === import_hwk_adapter_core4.HardwareErrorCode.PayloadTooLarge && usbErrorOrigin !== "device") {
|
|
2213
2280
|
const displayDevice2 = toDeviceInfo(record);
|
|
2214
|
-
return this._requestQrDisplayAndAwaitResponse(
|
|
2215
|
-
|
|
2216
|
-
animated
|
|
2217
|
-
|
|
2281
|
+
return this._requestQrDisplayAndAwaitResponse(
|
|
2282
|
+
displayDevice2,
|
|
2283
|
+
{ ...requestUr, animated },
|
|
2284
|
+
signal
|
|
2285
|
+
);
|
|
2218
2286
|
}
|
|
2219
|
-
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;
|
|
2220
2288
|
if (!deviceAnswered) {
|
|
2221
2289
|
const lostSessionId = record.usbSessionId;
|
|
2222
2290
|
if (lostSessionId) {
|
|
@@ -2225,11 +2293,11 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2225
2293
|
record.usbSessionId = void 0;
|
|
2226
2294
|
if (interactionRoute) {
|
|
2227
2295
|
this._operations.end(interactionRoute.operationId, "disconnect");
|
|
2228
|
-
throw (0,
|
|
2229
|
-
code:
|
|
2296
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2297
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.OperationEnded,
|
|
2230
2298
|
message: operationName ? `Keystone ${operationName} may have completed before the USB connection was lost` : "Keystone operation USB connection was lost",
|
|
2231
2299
|
recovery: operationName ? { scope: "unknown" } : void 0,
|
|
2232
|
-
params: operationName ? (0,
|
|
2300
|
+
params: operationName ? (0, import_hwk_adapter_core4.operationMayHaveCompletedParams)(operationName, {
|
|
2233
2301
|
operationId: interactionRoute.operationId,
|
|
2234
2302
|
reason: "disconnect"
|
|
2235
2303
|
}) : {
|
|
@@ -2239,12 +2307,12 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2239
2307
|
});
|
|
2240
2308
|
}
|
|
2241
2309
|
if (operationName) {
|
|
2242
|
-
throw (0,
|
|
2243
|
-
code: usbErrorCode ??
|
|
2310
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2311
|
+
code: usbErrorCode ?? import_hwk_adapter_core4.HardwareErrorCode.TransportError,
|
|
2244
2312
|
message: `Keystone ${operationName} may have completed before the USB connection was lost`,
|
|
2245
2313
|
origin: "transport",
|
|
2246
2314
|
recovery: { scope: "unknown" },
|
|
2247
|
-
params: (0,
|
|
2315
|
+
params: (0, import_hwk_adapter_core4.operationMayHaveCompletedParams)(operationName)
|
|
2248
2316
|
});
|
|
2249
2317
|
}
|
|
2250
2318
|
}
|
|
@@ -2252,18 +2320,19 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2252
2320
|
}
|
|
2253
2321
|
const displayDevice = record ? toDeviceInfo(record) : placeholderDeviceInfo();
|
|
2254
2322
|
try {
|
|
2255
|
-
return await this._requestQrDisplayAndAwaitResponse(
|
|
2256
|
-
|
|
2257
|
-
animated
|
|
2258
|
-
|
|
2323
|
+
return await this._requestQrDisplayAndAwaitResponse(
|
|
2324
|
+
displayDevice,
|
|
2325
|
+
{ ...requestUr, animated },
|
|
2326
|
+
signal
|
|
2327
|
+
);
|
|
2259
2328
|
} catch (error) {
|
|
2260
2329
|
const { code, _tag: tag } = error;
|
|
2261
|
-
if (operationName && (code ===
|
|
2262
|
-
throw (0,
|
|
2263
|
-
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,
|
|
2264
2333
|
message: `Keystone ${operationName} may have completed before the QR response timed out`,
|
|
2265
2334
|
recovery: { scope: "unknown" },
|
|
2266
|
-
params: (0,
|
|
2335
|
+
params: (0, import_hwk_adapter_core4.operationMayHaveCompletedParams)(operationName)
|
|
2267
2336
|
});
|
|
2268
2337
|
}
|
|
2269
2338
|
throw error;
|
|
@@ -2315,8 +2384,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2315
2384
|
let record;
|
|
2316
2385
|
if (resolvedViaUsb && existingRecord) {
|
|
2317
2386
|
if (parsed.masterFingerprint !== existingRecord.masterFingerprint) {
|
|
2318
|
-
throw (0,
|
|
2319
|
-
code:
|
|
2387
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2388
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2320
2389
|
message: "Keystone USB account export returned a different master fingerprint"
|
|
2321
2390
|
});
|
|
2322
2391
|
}
|
|
@@ -2329,8 +2398,8 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2329
2398
|
}
|
|
2330
2399
|
const account = parsed.accounts.find((a) => normalizePath(a.path) === syncPath);
|
|
2331
2400
|
if (!account) {
|
|
2332
|
-
throw (0,
|
|
2333
|
-
code:
|
|
2401
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2402
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2334
2403
|
message: `Keystone did not return the requested derivation path (${syncPath})`
|
|
2335
2404
|
});
|
|
2336
2405
|
}
|
|
@@ -2371,7 +2440,7 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2371
2440
|
const attached = await this._tryUsbAttach(target.expectedWalletId);
|
|
2372
2441
|
_KeystoneAdapter._throwIfAborted(signal);
|
|
2373
2442
|
if (attached) return { record: attached };
|
|
2374
|
-
const { accountPath } = splitAccountPath(
|
|
2443
|
+
const { accountPath } = splitAccountPath(import_hwk_adapter_core4.CHAIN_FINGERPRINT_PATHS[chain]);
|
|
2375
2444
|
const schemas = accountPath === KEYSTONE_WALLET_ID_PATH ? [{ path: KEYSTONE_WALLET_ID_PATH, curve: "secp256k1" }] : [
|
|
2376
2445
|
{ path: KEYSTONE_WALLET_ID_PATH, curve: "secp256k1" },
|
|
2377
2446
|
{
|
|
@@ -2390,43 +2459,97 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2390
2459
|
const record = this._upsertDeviceRecord(parsed);
|
|
2391
2460
|
return { record };
|
|
2392
2461
|
}
|
|
2393
|
-
|
|
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();
|
|
2394
2506
|
const waitPromise = this._uiRegistry.wait(
|
|
2395
|
-
|
|
2396
|
-
{ timeoutMs: this._qrTimeoutMs }
|
|
2507
|
+
import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2508
|
+
{ timeoutMs: this._qrTimeoutMs, operationId }
|
|
2397
2509
|
);
|
|
2398
|
-
this.emitter.emit(
|
|
2399
|
-
type:
|
|
2400
|
-
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 }
|
|
2401
2513
|
});
|
|
2402
|
-
const response = await
|
|
2514
|
+
const response = await this._awaitQrResponse(
|
|
2515
|
+
import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_DISPLAY,
|
|
2516
|
+
waitPromise,
|
|
2517
|
+
signal
|
|
2518
|
+
);
|
|
2403
2519
|
return { urType: response.urType, urData: response.urData };
|
|
2404
2520
|
}
|
|
2405
|
-
async _requestQrScanAndAwaitResponse(device) {
|
|
2521
|
+
async _requestQrScanAndAwaitResponse(device, signal) {
|
|
2522
|
+
const operationId = this._activeOperationId();
|
|
2406
2523
|
const waitPromise = this._uiRegistry.wait(
|
|
2407
|
-
|
|
2408
|
-
{ timeoutMs: this._qrTimeoutMs }
|
|
2524
|
+
import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_SCAN,
|
|
2525
|
+
{ timeoutMs: this._qrTimeoutMs, operationId }
|
|
2409
2526
|
);
|
|
2410
|
-
this.emitter.emit(
|
|
2411
|
-
type:
|
|
2412
|
-
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 }
|
|
2413
2530
|
});
|
|
2414
|
-
const response = await waitPromise;
|
|
2531
|
+
const response = await this._awaitQrResponse(import_hwk_adapter_core4.UI_REQUEST.REQUEST_QR_SCAN, waitPromise, signal);
|
|
2415
2532
|
return { urType: response.urType, urData: response.urData };
|
|
2416
2533
|
}
|
|
2417
2534
|
async _callUsbConnector(sessionId, method, params, signal) {
|
|
2418
2535
|
if (!this._usbConnector) {
|
|
2419
|
-
throw (0,
|
|
2420
|
-
code:
|
|
2536
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2537
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.TransportNotAvailable,
|
|
2421
2538
|
message: "No USB connector configured for this Keystone adapter"
|
|
2422
2539
|
});
|
|
2423
2540
|
}
|
|
2424
2541
|
if (this._pendingUsbTeardowns > 0 || this._unsettledUsbOperations.size > 0) {
|
|
2425
|
-
throw (0,
|
|
2426
|
-
code:
|
|
2542
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2543
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceBusyInternal,
|
|
2427
2544
|
message: `Keystone USB is busy while calling ${method}`
|
|
2428
2545
|
});
|
|
2429
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
|
+
}
|
|
2430
2553
|
const releaseOperation = this._retainUsbOperation(`call:${sessionId}`);
|
|
2431
2554
|
let rawCall;
|
|
2432
2555
|
try {
|
|
@@ -2508,16 +2631,16 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2508
2631
|
}
|
|
2509
2632
|
static _assertRequestIdMatches(expected, actual) {
|
|
2510
2633
|
if (actual && actual.toLowerCase() !== expected.toLowerCase()) {
|
|
2511
|
-
throw (0,
|
|
2512
|
-
code:
|
|
2634
|
+
throw (0, import_hwk_adapter_core4.createHwkError)({
|
|
2635
|
+
code: import_hwk_adapter_core4.HardwareErrorCode.DeviceMismatch,
|
|
2513
2636
|
message: "Keystone response requestId does not match the pending request \u2014 discarding a stale or unrelated scan"
|
|
2514
2637
|
});
|
|
2515
2638
|
}
|
|
2516
2639
|
}
|
|
2517
2640
|
_unsupported(method, reason) {
|
|
2518
2641
|
return Promise.resolve(
|
|
2519
|
-
(0,
|
|
2520
|
-
|
|
2642
|
+
(0, import_hwk_adapter_core4.failure)(
|
|
2643
|
+
import_hwk_adapter_core4.HardwareErrorCode.MethodNotSupported,
|
|
2521
2644
|
`KeystoneAdapter.${method} is not implemented yet: ${reason}`
|
|
2522
2645
|
)
|
|
2523
2646
|
);
|
|
@@ -2527,30 +2650,30 @@ var KeystoneAdapter = class _KeystoneAdapter {
|
|
|
2527
2650
|
const e = err;
|
|
2528
2651
|
if (typeof e.code === "number" && e.code >= 1e4 && e.code <= 99999) {
|
|
2529
2652
|
const { origin } = e;
|
|
2530
|
-
return (0,
|
|
2653
|
+
return (0, import_hwk_adapter_core4.failure)(
|
|
2531
2654
|
e.code,
|
|
2532
2655
|
e.message ?? "Unknown error",
|
|
2533
2656
|
e.params,
|
|
2534
2657
|
origin === "device" || origin === "transport" || origin === "host" ? origin : void 0,
|
|
2535
|
-
(0,
|
|
2658
|
+
(0, import_hwk_adapter_core4.isHwkRecoveryHint)(e.recovery) ? e.recovery : void 0
|
|
2536
2659
|
);
|
|
2537
2660
|
}
|
|
2538
|
-
if (e._tag ===
|
|
2539
|
-
return (0,
|
|
2540
|
-
|
|
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,
|
|
2541
2664
|
e.message ?? "Keystone QR operation was cancelled"
|
|
2542
2665
|
);
|
|
2543
2666
|
}
|
|
2544
|
-
if (e._tag ===
|
|
2545
|
-
return (0,
|
|
2546
|
-
|
|
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,
|
|
2547
2670
|
e.message ?? "Keystone QR operation timed out"
|
|
2548
2671
|
);
|
|
2549
2672
|
}
|
|
2550
2673
|
}
|
|
2551
2674
|
const message = err instanceof Error ? err.message : String(err);
|
|
2552
2675
|
const params = err instanceof Error && err.stack ? { stack: err.stack } : void 0;
|
|
2553
|
-
return (0,
|
|
2676
|
+
return (0, import_hwk_adapter_core4.failure)(import_hwk_adapter_core4.HardwareErrorCode.UnknownError, message, params);
|
|
2554
2677
|
}
|
|
2555
2678
|
};
|
|
2556
2679
|
// Annotate the CommonJS export names for ESM import in node:
|