@nightlylabs/dex-sdk 0.3.1 → 0.3.2
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/TransportWebHID-QH5HRZY3.js +225 -0
- package/dist/TransportWebUSB-CZSRX7MB.js +258 -0
- package/dist/chunk-DOLYMX7P.js +1955 -0
- package/dist/chunk-ISCCOOHD.js +930 -0
- package/dist/index.cjs +13357 -149765
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +17205 -153639
- package/package.json +1 -1
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__toESM,
|
|
3
|
+
require_semver
|
|
4
|
+
} from "./chunk-DOLYMX7P.js";
|
|
5
|
+
|
|
6
|
+
// node_modules/.pnpm/@ledgerhq+errors@6.19.1/node_modules/@ledgerhq/errors/lib-es/helpers.js
|
|
7
|
+
var errorClasses = {};
|
|
8
|
+
var deserializers = {};
|
|
9
|
+
var addCustomErrorDeserializer = (name, deserializer) => {
|
|
10
|
+
deserializers[name] = deserializer;
|
|
11
|
+
};
|
|
12
|
+
var createCustomErrorClass = (name) => {
|
|
13
|
+
class CustomErrorClass extends Error {
|
|
14
|
+
constructor(message, fields, options) {
|
|
15
|
+
super(message || name, options);
|
|
16
|
+
Object.setPrototypeOf(this, CustomErrorClass.prototype);
|
|
17
|
+
this.name = name;
|
|
18
|
+
if (fields) {
|
|
19
|
+
for (const k in fields) {
|
|
20
|
+
this[k] = fields[k];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (options && isObject(options) && "cause" in options && !("cause" in this)) {
|
|
24
|
+
const cause = options.cause;
|
|
25
|
+
this.cause = cause;
|
|
26
|
+
if ("stack" in cause) {
|
|
27
|
+
this.stack = this.stack + "\nCAUSE: " + cause.stack;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
errorClasses[name] = CustomErrorClass;
|
|
33
|
+
return CustomErrorClass;
|
|
34
|
+
};
|
|
35
|
+
function isObject(value) {
|
|
36
|
+
return typeof value === "object";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// node_modules/.pnpm/@ledgerhq+errors@6.19.1/node_modules/@ledgerhq/errors/lib-es/index.js
|
|
40
|
+
var AccountNameRequiredError = createCustomErrorClass("AccountNameRequired");
|
|
41
|
+
var AccountNotSupported = createCustomErrorClass("AccountNotSupported");
|
|
42
|
+
var AccountAwaitingSendPendingOperations = createCustomErrorClass("AccountAwaitingSendPendingOperations");
|
|
43
|
+
var AmountRequired = createCustomErrorClass("AmountRequired");
|
|
44
|
+
var BluetoothRequired = createCustomErrorClass("BluetoothRequired");
|
|
45
|
+
var BtcUnmatchedApp = createCustomErrorClass("BtcUnmatchedApp");
|
|
46
|
+
var CantOpenDevice = createCustomErrorClass("CantOpenDevice");
|
|
47
|
+
var CashAddrNotSupported = createCustomErrorClass("CashAddrNotSupported");
|
|
48
|
+
var ClaimRewardsFeesWarning = createCustomErrorClass("ClaimRewardsFeesWarning");
|
|
49
|
+
var CurrencyNotSupported = createCustomErrorClass("CurrencyNotSupported");
|
|
50
|
+
var DeviceAppVerifyNotSupported = createCustomErrorClass("DeviceAppVerifyNotSupported");
|
|
51
|
+
var DeviceGenuineSocketEarlyClose = createCustomErrorClass("DeviceGenuineSocketEarlyClose");
|
|
52
|
+
var DeviceNotGenuineError = createCustomErrorClass("DeviceNotGenuine");
|
|
53
|
+
var DeviceOnDashboardExpected = createCustomErrorClass("DeviceOnDashboardExpected");
|
|
54
|
+
var DeviceOnDashboardUnexpected = createCustomErrorClass("DeviceOnDashboardUnexpected");
|
|
55
|
+
var DeviceInOSUExpected = createCustomErrorClass("DeviceInOSUExpected");
|
|
56
|
+
var DeviceHalted = createCustomErrorClass("DeviceHalted");
|
|
57
|
+
var DeviceNameInvalid = createCustomErrorClass("DeviceNameInvalid");
|
|
58
|
+
var DeviceSocketFail = createCustomErrorClass("DeviceSocketFail");
|
|
59
|
+
var DeviceSocketNoBulkStatus = createCustomErrorClass("DeviceSocketNoBulkStatus");
|
|
60
|
+
var DeviceNeedsRestart = createCustomErrorClass("DeviceSocketNoBulkStatus");
|
|
61
|
+
var UnresponsiveDeviceError = createCustomErrorClass("UnresponsiveDeviceError");
|
|
62
|
+
var DisconnectedDevice = createCustomErrorClass("DisconnectedDevice");
|
|
63
|
+
var DisconnectedDeviceDuringOperation = createCustomErrorClass("DisconnectedDeviceDuringOperation");
|
|
64
|
+
var DeviceExtractOnboardingStateError = createCustomErrorClass("DeviceExtractOnboardingStateError");
|
|
65
|
+
var DeviceOnboardingStatePollingError = createCustomErrorClass("DeviceOnboardingStatePollingError");
|
|
66
|
+
var EnpointConfigError = createCustomErrorClass("EnpointConfig");
|
|
67
|
+
var EthAppPleaseEnableContractData = createCustomErrorClass("EthAppPleaseEnableContractData");
|
|
68
|
+
var FeeEstimationFailed = createCustomErrorClass("FeeEstimationFailed");
|
|
69
|
+
var FirmwareNotRecognized = createCustomErrorClass("FirmwareNotRecognized");
|
|
70
|
+
var HardResetFail = createCustomErrorClass("HardResetFail");
|
|
71
|
+
var InvalidXRPTag = createCustomErrorClass("InvalidXRPTag");
|
|
72
|
+
var InvalidAddress = createCustomErrorClass("InvalidAddress");
|
|
73
|
+
var InvalidNonce = createCustomErrorClass("InvalidNonce");
|
|
74
|
+
var InvalidAddressBecauseDestinationIsAlsoSource = createCustomErrorClass("InvalidAddressBecauseDestinationIsAlsoSource");
|
|
75
|
+
var LatestMCUInstalledError = createCustomErrorClass("LatestMCUInstalledError");
|
|
76
|
+
var UnknownMCU = createCustomErrorClass("UnknownMCU");
|
|
77
|
+
var LedgerAPIError = createCustomErrorClass("LedgerAPIError");
|
|
78
|
+
var LedgerAPIErrorWithMessage = createCustomErrorClass("LedgerAPIErrorWithMessage");
|
|
79
|
+
var LedgerAPINotAvailable = createCustomErrorClass("LedgerAPINotAvailable");
|
|
80
|
+
var ManagerAppAlreadyInstalledError = createCustomErrorClass("ManagerAppAlreadyInstalled");
|
|
81
|
+
var ManagerAppRelyOnBTCError = createCustomErrorClass("ManagerAppRelyOnBTC");
|
|
82
|
+
var ManagerAppDepInstallRequired = createCustomErrorClass("ManagerAppDepInstallRequired");
|
|
83
|
+
var ManagerAppDepUninstallRequired = createCustomErrorClass("ManagerAppDepUninstallRequired");
|
|
84
|
+
var ManagerDeviceLockedError = createCustomErrorClass("ManagerDeviceLocked");
|
|
85
|
+
var ManagerFirmwareNotEnoughSpaceError = createCustomErrorClass("ManagerFirmwareNotEnoughSpace");
|
|
86
|
+
var ManagerNotEnoughSpaceError = createCustomErrorClass("ManagerNotEnoughSpace");
|
|
87
|
+
var ManagerUninstallBTCDep = createCustomErrorClass("ManagerUninstallBTCDep");
|
|
88
|
+
var NetworkDown = createCustomErrorClass("NetworkDown");
|
|
89
|
+
var NetworkError = createCustomErrorClass("NetworkError");
|
|
90
|
+
var NoAddressesFound = createCustomErrorClass("NoAddressesFound");
|
|
91
|
+
var NotEnoughBalance = createCustomErrorClass("NotEnoughBalance");
|
|
92
|
+
var NotEnoughBalanceSwap = createCustomErrorClass("NotEnoughBalanceSwap");
|
|
93
|
+
var NotEnoughBalanceToDelegate = createCustomErrorClass("NotEnoughBalanceToDelegate");
|
|
94
|
+
var NotEnoughBalanceInParentAccount = createCustomErrorClass("NotEnoughBalanceInParentAccount");
|
|
95
|
+
var NotEnoughSpendableBalance = createCustomErrorClass("NotEnoughSpendableBalance");
|
|
96
|
+
var NotEnoughBalanceBecauseDestinationNotCreated = createCustomErrorClass("NotEnoughBalanceBecauseDestinationNotCreated");
|
|
97
|
+
var NoAccessToCamera = createCustomErrorClass("NoAccessToCamera");
|
|
98
|
+
var NotEnoughGas = createCustomErrorClass("NotEnoughGas");
|
|
99
|
+
var NotEnoughGasSwap = createCustomErrorClass("NotEnoughGasSwap");
|
|
100
|
+
var TronEmptyAccount = createCustomErrorClass("TronEmptyAccount");
|
|
101
|
+
var MaybeKeepTronAccountAlive = createCustomErrorClass("MaybeKeepTronAccountAlive");
|
|
102
|
+
var NotSupportedLegacyAddress = createCustomErrorClass("NotSupportedLegacyAddress");
|
|
103
|
+
var GasLessThanEstimate = createCustomErrorClass("GasLessThanEstimate");
|
|
104
|
+
var PriorityFeeTooLow = createCustomErrorClass("PriorityFeeTooLow");
|
|
105
|
+
var PriorityFeeTooHigh = createCustomErrorClass("PriorityFeeTooHigh");
|
|
106
|
+
var PriorityFeeHigherThanMaxFee = createCustomErrorClass("PriorityFeeHigherThanMaxFee");
|
|
107
|
+
var MaxFeeTooLow = createCustomErrorClass("MaxFeeTooLow");
|
|
108
|
+
var PasswordsDontMatchError = createCustomErrorClass("PasswordsDontMatch");
|
|
109
|
+
var PasswordIncorrectError = createCustomErrorClass("PasswordIncorrect");
|
|
110
|
+
var RecommendSubAccountsToEmpty = createCustomErrorClass("RecommendSubAccountsToEmpty");
|
|
111
|
+
var RecommendUndelegation = createCustomErrorClass("RecommendUndelegation");
|
|
112
|
+
var TimeoutTagged = createCustomErrorClass("TimeoutTagged");
|
|
113
|
+
var UnexpectedBootloader = createCustomErrorClass("UnexpectedBootloader");
|
|
114
|
+
var MCUNotGenuineToDashboard = createCustomErrorClass("MCUNotGenuineToDashboard");
|
|
115
|
+
var RecipientRequired = createCustomErrorClass("RecipientRequired");
|
|
116
|
+
var UnavailableTezosOriginatedAccountReceive = createCustomErrorClass("UnavailableTezosOriginatedAccountReceive");
|
|
117
|
+
var UnavailableTezosOriginatedAccountSend = createCustomErrorClass("UnavailableTezosOriginatedAccountSend");
|
|
118
|
+
var UpdateFetchFileFail = createCustomErrorClass("UpdateFetchFileFail");
|
|
119
|
+
var UpdateIncorrectHash = createCustomErrorClass("UpdateIncorrectHash");
|
|
120
|
+
var UpdateIncorrectSig = createCustomErrorClass("UpdateIncorrectSig");
|
|
121
|
+
var UpdateYourApp = createCustomErrorClass("UpdateYourApp");
|
|
122
|
+
var UserRefusedDeviceNameChange = createCustomErrorClass("UserRefusedDeviceNameChange");
|
|
123
|
+
var UserRefusedAddress = createCustomErrorClass("UserRefusedAddress");
|
|
124
|
+
var UserRefusedFirmwareUpdate = createCustomErrorClass("UserRefusedFirmwareUpdate");
|
|
125
|
+
var UserRefusedAllowManager = createCustomErrorClass("UserRefusedAllowManager");
|
|
126
|
+
var UserRefusedOnDevice = createCustomErrorClass("UserRefusedOnDevice");
|
|
127
|
+
var PinNotSet = createCustomErrorClass("PinNotSet");
|
|
128
|
+
var ExpertModeRequired = createCustomErrorClass("ExpertModeRequired");
|
|
129
|
+
var TransportOpenUserCancelled = createCustomErrorClass("TransportOpenUserCancelled");
|
|
130
|
+
var TransportInterfaceNotAvailable = createCustomErrorClass("TransportInterfaceNotAvailable");
|
|
131
|
+
var TransportRaceCondition = createCustomErrorClass("TransportRaceCondition");
|
|
132
|
+
var TransportWebUSBGestureRequired = createCustomErrorClass("TransportWebUSBGestureRequired");
|
|
133
|
+
var TransactionHasBeenValidatedError = createCustomErrorClass("TransactionHasBeenValidatedError");
|
|
134
|
+
var TransportExchangeTimeoutError = createCustomErrorClass("TransportExchangeTimeoutError");
|
|
135
|
+
var DeviceShouldStayInApp = createCustomErrorClass("DeviceShouldStayInApp");
|
|
136
|
+
var WebsocketConnectionError = createCustomErrorClass("WebsocketConnectionError");
|
|
137
|
+
var WebsocketConnectionFailed = createCustomErrorClass("WebsocketConnectionFailed");
|
|
138
|
+
var WrongDeviceForAccount = createCustomErrorClass("WrongDeviceForAccount");
|
|
139
|
+
var WrongDeviceForAccountPayout = createCustomErrorClass("WrongDeviceForAccountPayout");
|
|
140
|
+
var WrongDeviceForAccountRefund = createCustomErrorClass("WrongDeviceForAccountRefund");
|
|
141
|
+
var WrongAppForCurrency = createCustomErrorClass("WrongAppForCurrency");
|
|
142
|
+
var ETHAddressNonEIP = createCustomErrorClass("ETHAddressNonEIP");
|
|
143
|
+
var CantScanQRCode = createCustomErrorClass("CantScanQRCode");
|
|
144
|
+
var FeeNotLoaded = createCustomErrorClass("FeeNotLoaded");
|
|
145
|
+
var FeeNotLoadedSwap = createCustomErrorClass("FeeNotLoadedSwap");
|
|
146
|
+
var FeeRequired = createCustomErrorClass("FeeRequired");
|
|
147
|
+
var FeeTooHigh = createCustomErrorClass("FeeTooHigh");
|
|
148
|
+
var PendingOperation = createCustomErrorClass("PendingOperation");
|
|
149
|
+
var SyncError = createCustomErrorClass("SyncError");
|
|
150
|
+
var PairingFailed = createCustomErrorClass("PairingFailed");
|
|
151
|
+
var PeerRemovedPairing = createCustomErrorClass("PeerRemovedPairing");
|
|
152
|
+
var GenuineCheckFailed = createCustomErrorClass("GenuineCheckFailed");
|
|
153
|
+
var LedgerAPI4xx = createCustomErrorClass("LedgerAPI4xx");
|
|
154
|
+
var LedgerAPI5xx = createCustomErrorClass("LedgerAPI5xx");
|
|
155
|
+
var FirmwareOrAppUpdateRequired = createCustomErrorClass("FirmwareOrAppUpdateRequired");
|
|
156
|
+
var ReplacementTransactionUnderpriced = createCustomErrorClass("ReplacementTransactionUnderpriced");
|
|
157
|
+
var OpReturnDataSizeLimit = createCustomErrorClass("OpReturnSizeLimit");
|
|
158
|
+
var DustLimit = createCustomErrorClass("DustLimit");
|
|
159
|
+
var LanguageNotFound = createCustomErrorClass("LanguageNotFound");
|
|
160
|
+
var NoDBPathGiven = createCustomErrorClass("NoDBPathGiven");
|
|
161
|
+
var DBWrongPassword = createCustomErrorClass("DBWrongPassword");
|
|
162
|
+
var DBNotReset = createCustomErrorClass("DBNotReset");
|
|
163
|
+
var SequenceNumberError = createCustomErrorClass("SequenceNumberError");
|
|
164
|
+
var DisabledTransactionBroadcastError = createCustomErrorClass("DisabledTransactionBroadcastError");
|
|
165
|
+
var HwTransportErrorType;
|
|
166
|
+
(function(HwTransportErrorType2) {
|
|
167
|
+
HwTransportErrorType2["Unknown"] = "Unknown";
|
|
168
|
+
HwTransportErrorType2["LocationServicesDisabled"] = "LocationServicesDisabled";
|
|
169
|
+
HwTransportErrorType2["LocationServicesUnauthorized"] = "LocationServicesUnauthorized";
|
|
170
|
+
HwTransportErrorType2["BluetoothScanStartFailed"] = "BluetoothScanStartFailed";
|
|
171
|
+
})(HwTransportErrorType || (HwTransportErrorType = {}));
|
|
172
|
+
var TransportError = class extends Error {
|
|
173
|
+
constructor(message, id2) {
|
|
174
|
+
const name = "TransportError";
|
|
175
|
+
super(message || name);
|
|
176
|
+
this.name = name;
|
|
177
|
+
this.message = message;
|
|
178
|
+
this.stack = new Error(message).stack;
|
|
179
|
+
this.id = id2;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
addCustomErrorDeserializer("TransportError", (e) => new TransportError(e.message, e.id));
|
|
183
|
+
var StatusCodes = {
|
|
184
|
+
ACCESS_CONDITION_NOT_FULFILLED: 38916,
|
|
185
|
+
ALGORITHM_NOT_SUPPORTED: 38020,
|
|
186
|
+
CLA_NOT_SUPPORTED: 28160,
|
|
187
|
+
CODE_BLOCKED: 38976,
|
|
188
|
+
CODE_NOT_INITIALIZED: 38914,
|
|
189
|
+
COMMAND_INCOMPATIBLE_FILE_STRUCTURE: 27009,
|
|
190
|
+
CONDITIONS_OF_USE_NOT_SATISFIED: 27013,
|
|
191
|
+
CONTRADICTION_INVALIDATION: 38928,
|
|
192
|
+
CONTRADICTION_SECRET_CODE_STATUS: 38920,
|
|
193
|
+
DEVICE_IN_RECOVERY_MODE: 26159,
|
|
194
|
+
CUSTOM_IMAGE_EMPTY: 26158,
|
|
195
|
+
FILE_ALREADY_EXISTS: 27273,
|
|
196
|
+
FILE_NOT_FOUND: 37892,
|
|
197
|
+
GP_AUTH_FAILED: 25344,
|
|
198
|
+
HALTED: 28586,
|
|
199
|
+
INCONSISTENT_FILE: 37896,
|
|
200
|
+
INCORRECT_DATA: 27264,
|
|
201
|
+
INCORRECT_LENGTH: 26368,
|
|
202
|
+
INCORRECT_P1_P2: 27392,
|
|
203
|
+
INS_NOT_SUPPORTED: 27904,
|
|
204
|
+
DEVICE_NOT_ONBOARDED: 27911,
|
|
205
|
+
DEVICE_NOT_ONBOARDED_2: 26129,
|
|
206
|
+
INVALID_KCV: 38021,
|
|
207
|
+
INVALID_OFFSET: 37890,
|
|
208
|
+
LICENSING: 28482,
|
|
209
|
+
LOCKED_DEVICE: 21781,
|
|
210
|
+
MAX_VALUE_REACHED: 38992,
|
|
211
|
+
MEMORY_PROBLEM: 37440,
|
|
212
|
+
MISSING_CRITICAL_PARAMETER: 26624,
|
|
213
|
+
NO_EF_SELECTED: 37888,
|
|
214
|
+
NOT_ENOUGH_MEMORY_SPACE: 27268,
|
|
215
|
+
OK: 36864,
|
|
216
|
+
PIN_REMAINING_ATTEMPTS: 25536,
|
|
217
|
+
REFERENCED_DATA_NOT_FOUND: 27272,
|
|
218
|
+
SECURITY_STATUS_NOT_SATISFIED: 27010,
|
|
219
|
+
TECHNICAL_PROBLEM: 28416,
|
|
220
|
+
UNKNOWN_APDU: 27906,
|
|
221
|
+
USER_REFUSED_ON_DEVICE: 21761,
|
|
222
|
+
NOT_ENOUGH_SPACE: 20738,
|
|
223
|
+
APP_NOT_FOUND_OR_INVALID_CONTEXT: 20771,
|
|
224
|
+
INVALID_APP_NAME_LENGTH: 26378,
|
|
225
|
+
GEN_AES_KEY_FAILED: 21529,
|
|
226
|
+
INTERNAL_CRYPTO_OPERATION_FAILED: 21530,
|
|
227
|
+
INTERNAL_COMPUTE_AES_CMAC_FAILED: 21531,
|
|
228
|
+
ENCRYPT_APP_STORAGE_FAILED: 21532,
|
|
229
|
+
INVALID_BACKUP_STATE: 26178,
|
|
230
|
+
PIN_NOT_SET: 21762,
|
|
231
|
+
INVALID_BACKUP_LENGTH: 26419,
|
|
232
|
+
INVALID_RESTORE_STATE: 26179,
|
|
233
|
+
INVALID_CHUNK_LENGTH: 26420,
|
|
234
|
+
INVALID_BACKUP_HEADER: 26698,
|
|
235
|
+
// Not documented:
|
|
236
|
+
TRUSTCHAIN_WRONG_SEED: 45063
|
|
237
|
+
};
|
|
238
|
+
function getAltStatusMessage(code) {
|
|
239
|
+
switch (code) {
|
|
240
|
+
// improve text of most common errors
|
|
241
|
+
case 26368:
|
|
242
|
+
return "Incorrect length";
|
|
243
|
+
case 26624:
|
|
244
|
+
return "Missing critical parameter";
|
|
245
|
+
case 27010:
|
|
246
|
+
return "Security not satisfied (dongle locked or have invalid access rights)";
|
|
247
|
+
case 27013:
|
|
248
|
+
return "Condition of use not satisfied (denied by the user?)";
|
|
249
|
+
case 27264:
|
|
250
|
+
return "Invalid data received";
|
|
251
|
+
case 27392:
|
|
252
|
+
return "Invalid parameter received";
|
|
253
|
+
case 21781:
|
|
254
|
+
return "Locked device";
|
|
255
|
+
}
|
|
256
|
+
if (28416 <= code && code <= 28671) {
|
|
257
|
+
return "Internal error, please report";
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
var TransportStatusError = class _TransportStatusError extends Error {
|
|
261
|
+
/**
|
|
262
|
+
* @param statusCode The error status code coming from a Transport implementation
|
|
263
|
+
* @param options containing:
|
|
264
|
+
* - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it
|
|
265
|
+
* . Ex: LockedDeviceError. Default to true.
|
|
266
|
+
*/
|
|
267
|
+
constructor(statusCode, { canBeMappedToChildError = true } = {}) {
|
|
268
|
+
const statusText = Object.keys(StatusCodes).find((k) => StatusCodes[k] === statusCode) || "UNKNOWN_ERROR";
|
|
269
|
+
const smsg = getAltStatusMessage(statusCode) || statusText;
|
|
270
|
+
const statusCodeStr = statusCode.toString(16);
|
|
271
|
+
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`;
|
|
272
|
+
super(message);
|
|
273
|
+
this.name = "TransportStatusError";
|
|
274
|
+
this.statusCode = statusCode;
|
|
275
|
+
this.statusText = statusText;
|
|
276
|
+
Object.setPrototypeOf(this, _TransportStatusError.prototype);
|
|
277
|
+
if (canBeMappedToChildError && statusCode === StatusCodes.LOCKED_DEVICE) {
|
|
278
|
+
return new LockedDeviceError(message);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var LockedDeviceError = class _LockedDeviceError extends TransportStatusError {
|
|
283
|
+
constructor(message) {
|
|
284
|
+
super(StatusCodes.LOCKED_DEVICE, { canBeMappedToChildError: false });
|
|
285
|
+
if (message) {
|
|
286
|
+
this.message = message;
|
|
287
|
+
}
|
|
288
|
+
this.name = "LockedDeviceError";
|
|
289
|
+
Object.setPrototypeOf(this, _LockedDeviceError.prototype);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
addCustomErrorDeserializer("TransportStatusError", (e) => new TransportStatusError(e.statusCode));
|
|
293
|
+
|
|
294
|
+
// node_modules/.pnpm/@ledgerhq+logs@6.12.0/node_modules/@ledgerhq/logs/lib-es/index.js
|
|
295
|
+
var id = 0;
|
|
296
|
+
var subscribers = [];
|
|
297
|
+
var log = (type, message, data) => {
|
|
298
|
+
const obj = {
|
|
299
|
+
type,
|
|
300
|
+
id: String(++id),
|
|
301
|
+
date: /* @__PURE__ */ new Date()
|
|
302
|
+
};
|
|
303
|
+
if (message)
|
|
304
|
+
obj.message = message;
|
|
305
|
+
if (data)
|
|
306
|
+
obj.data = data;
|
|
307
|
+
dispatch(obj);
|
|
308
|
+
};
|
|
309
|
+
var trace = ({ type, message, data, context }) => {
|
|
310
|
+
const obj = {
|
|
311
|
+
type,
|
|
312
|
+
id: String(++id),
|
|
313
|
+
date: /* @__PURE__ */ new Date()
|
|
314
|
+
};
|
|
315
|
+
if (message)
|
|
316
|
+
obj.message = message;
|
|
317
|
+
if (data)
|
|
318
|
+
obj.data = data;
|
|
319
|
+
if (context)
|
|
320
|
+
obj.context = context;
|
|
321
|
+
dispatch(obj);
|
|
322
|
+
};
|
|
323
|
+
var LocalTracer = class _LocalTracer {
|
|
324
|
+
constructor(type, context) {
|
|
325
|
+
this.type = type;
|
|
326
|
+
this.context = context;
|
|
327
|
+
}
|
|
328
|
+
trace(message, data) {
|
|
329
|
+
trace({
|
|
330
|
+
type: this.type,
|
|
331
|
+
message,
|
|
332
|
+
data,
|
|
333
|
+
context: this.context
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
getContext() {
|
|
337
|
+
return this.context;
|
|
338
|
+
}
|
|
339
|
+
setContext(context) {
|
|
340
|
+
this.context = context;
|
|
341
|
+
}
|
|
342
|
+
updateContext(contextToAdd) {
|
|
343
|
+
this.context = Object.assign(Object.assign({}, this.context), contextToAdd);
|
|
344
|
+
}
|
|
345
|
+
getType() {
|
|
346
|
+
return this.type;
|
|
347
|
+
}
|
|
348
|
+
setType(type) {
|
|
349
|
+
this.type = type;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Create a new instance of the LocalTracer with an updated `type`
|
|
353
|
+
*
|
|
354
|
+
* It does not mutate the calling instance, but returns a new LocalTracer,
|
|
355
|
+
* following a simple builder pattern.
|
|
356
|
+
*/
|
|
357
|
+
withType(type) {
|
|
358
|
+
return new _LocalTracer(type, this.context);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Create a new instance of the LocalTracer with a new `context`
|
|
362
|
+
*
|
|
363
|
+
* It does not mutate the calling instance, but returns a new LocalTracer,
|
|
364
|
+
* following a simple builder pattern.
|
|
365
|
+
*
|
|
366
|
+
* @param context A TraceContext, that can undefined to reset the context
|
|
367
|
+
*/
|
|
368
|
+
withContext(context) {
|
|
369
|
+
return new _LocalTracer(this.type, context);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Create a new instance of the LocalTracer with an updated `context`,
|
|
373
|
+
* on which an additional context is merged with the existing one.
|
|
374
|
+
*
|
|
375
|
+
* It does not mutate the calling instance, but returns a new LocalTracer,
|
|
376
|
+
* following a simple builder pattern.
|
|
377
|
+
*/
|
|
378
|
+
withUpdatedContext(contextToAdd) {
|
|
379
|
+
return new _LocalTracer(this.type, Object.assign(Object.assign({}, this.context), contextToAdd));
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var listen = (cb) => {
|
|
383
|
+
subscribers.push(cb);
|
|
384
|
+
return () => {
|
|
385
|
+
const i = subscribers.indexOf(cb);
|
|
386
|
+
if (i !== -1) {
|
|
387
|
+
subscribers[i] = subscribers[subscribers.length - 1];
|
|
388
|
+
subscribers.pop();
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
function dispatch(log2) {
|
|
393
|
+
for (let i = 0; i < subscribers.length; i++) {
|
|
394
|
+
try {
|
|
395
|
+
subscribers[i](log2);
|
|
396
|
+
} catch (e) {
|
|
397
|
+
console.error(e);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (typeof window !== "undefined") {
|
|
402
|
+
window.__ledgerLogsListen = listen;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// node_modules/.pnpm/@ledgerhq+hw-transport@6.31.4/node_modules/@ledgerhq/hw-transport/lib-es/Transport.js
|
|
406
|
+
import EventEmitter from "events";
|
|
407
|
+
var __awaiter = function(thisArg, _arguments, P, generator) {
|
|
408
|
+
function adopt(value) {
|
|
409
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
410
|
+
resolve(value);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
414
|
+
function fulfilled(value) {
|
|
415
|
+
try {
|
|
416
|
+
step(generator.next(value));
|
|
417
|
+
} catch (e) {
|
|
418
|
+
reject(e);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function rejected(value) {
|
|
422
|
+
try {
|
|
423
|
+
step(generator["throw"](value));
|
|
424
|
+
} catch (e) {
|
|
425
|
+
reject(e);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function step(result) {
|
|
429
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
430
|
+
}
|
|
431
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
var DEFAULT_LOG_TYPE = "transport";
|
|
435
|
+
var Transport = class {
|
|
436
|
+
constructor({ context, logType } = {}) {
|
|
437
|
+
this.exchangeTimeout = 3e4;
|
|
438
|
+
this.unresponsiveTimeout = 15e3;
|
|
439
|
+
this.deviceModel = null;
|
|
440
|
+
this._events = new EventEmitter();
|
|
441
|
+
this.send = (cla_1, ins_1, p1_1, p2_1, ...args_1) => __awaiter(this, [cla_1, ins_1, p1_1, p2_1, ...args_1], void 0, function* (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [StatusCodes.OK], { abortTimeoutMs } = {}) {
|
|
442
|
+
const tracer = this.tracer.withUpdatedContext({ function: "send" });
|
|
443
|
+
if (data.length >= 256) {
|
|
444
|
+
tracer.trace("data.length exceeded 256 bytes limit", { dataLength: data.length });
|
|
445
|
+
throw new TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
|
|
446
|
+
}
|
|
447
|
+
tracer.trace("Starting an exchange", { abortTimeoutMs });
|
|
448
|
+
const response = yield this.exchange(
|
|
449
|
+
// The size of the data is added in 1 byte just before `data`
|
|
450
|
+
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]),
|
|
451
|
+
{ abortTimeoutMs }
|
|
452
|
+
);
|
|
453
|
+
tracer.trace("Received response from exchange");
|
|
454
|
+
const sw = response.readUInt16BE(response.length - 2);
|
|
455
|
+
if (!statusList.some((s) => s === sw)) {
|
|
456
|
+
throw new TransportStatusError(sw);
|
|
457
|
+
}
|
|
458
|
+
return response;
|
|
459
|
+
});
|
|
460
|
+
this._appAPIlock = null;
|
|
461
|
+
this.tracer = new LocalTracer(logType !== null && logType !== void 0 ? logType : DEFAULT_LOG_TYPE, context);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Send data to the device using a low level API.
|
|
465
|
+
* It's recommended to use the "send" method for a higher level API.
|
|
466
|
+
* @param {Buffer} apdu - The data to send.
|
|
467
|
+
* @param {Object} options - Contains optional options for the exchange function
|
|
468
|
+
* - abortTimeoutMs: stop the exchange after a given timeout. Another timeout exists
|
|
469
|
+
* to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange.
|
|
470
|
+
* @returns {Promise<Buffer>} A promise that resolves with the response data from the device.
|
|
471
|
+
*/
|
|
472
|
+
exchange(_apdu, { abortTimeoutMs: _abortTimeoutMs } = {}) {
|
|
473
|
+
throw new Error("exchange not implemented");
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Send apdus in batch to the device using a low level API.
|
|
477
|
+
* The default implementation is to call exchange for each apdu.
|
|
478
|
+
* @param {Array<Buffer>} apdus - array of apdus to send.
|
|
479
|
+
* @param {Observer<Buffer>} observer - an observer that will receive the response of each apdu.
|
|
480
|
+
* @returns {Subscription} A Subscription object on which you can call ".unsubscribe()" to stop sending apdus.
|
|
481
|
+
*/
|
|
482
|
+
exchangeBulk(apdus, observer) {
|
|
483
|
+
let unsubscribed = false;
|
|
484
|
+
const unsubscribe = () => {
|
|
485
|
+
unsubscribed = true;
|
|
486
|
+
};
|
|
487
|
+
const main = () => __awaiter(this, void 0, void 0, function* () {
|
|
488
|
+
if (unsubscribed)
|
|
489
|
+
return;
|
|
490
|
+
for (const apdu of apdus) {
|
|
491
|
+
const r = yield this.exchange(apdu);
|
|
492
|
+
if (unsubscribed)
|
|
493
|
+
return;
|
|
494
|
+
const status = r.readUInt16BE(r.length - 2);
|
|
495
|
+
if (status !== StatusCodes.OK) {
|
|
496
|
+
throw new TransportStatusError(status);
|
|
497
|
+
}
|
|
498
|
+
observer.next(r);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
main().then(() => !unsubscribed && observer.complete(), (e) => !unsubscribed && observer.error(e));
|
|
502
|
+
return { unsubscribe };
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Set the "scramble key" for the next data exchanges with the device.
|
|
506
|
+
* Each app can have a different scramble key and it is set internally during instantiation.
|
|
507
|
+
* @param {string} key - The scramble key to set.
|
|
508
|
+
* deprecated This method is no longer needed for modern transports and should be migrated away from.
|
|
509
|
+
* no @ before deprecated as it breaks documentationjs on version 14.0.2
|
|
510
|
+
* https://github.com/documentationjs/documentation/issues/1596
|
|
511
|
+
*/
|
|
512
|
+
setScrambleKey(_key) {
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Close the connection with the device.
|
|
516
|
+
*
|
|
517
|
+
* Note: for certain transports (hw-transport-node-hid-singleton for ex), once the promise resolved,
|
|
518
|
+
* the transport instance is actually still cached, and the device is disconnected only after a defined timeout.
|
|
519
|
+
* But for the consumer of the Transport, this does not matter and it can consider the transport to be closed.
|
|
520
|
+
*
|
|
521
|
+
* @returns {Promise<void>} A promise that resolves when the transport is closed.
|
|
522
|
+
*/
|
|
523
|
+
close() {
|
|
524
|
+
return Promise.resolve();
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Listen for an event on the transport instance.
|
|
528
|
+
* Transport implementations may have specific events. Common events include:
|
|
529
|
+
* "disconnect" : triggered when the transport is disconnected.
|
|
530
|
+
* @param {string} eventName - The name of the event to listen for.
|
|
531
|
+
* @param {(...args: Array<any>) => any} cb - The callback function to be invoked when the event occurs.
|
|
532
|
+
*/
|
|
533
|
+
on(eventName, cb) {
|
|
534
|
+
this._events.on(eventName, cb);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Stop listening to an event on an instance of transport.
|
|
538
|
+
*/
|
|
539
|
+
off(eventName, cb) {
|
|
540
|
+
this._events.removeListener(eventName, cb);
|
|
541
|
+
}
|
|
542
|
+
emit(event, ...args) {
|
|
543
|
+
this._events.emit(event, ...args);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Enable or not logs of the binary exchange
|
|
547
|
+
*/
|
|
548
|
+
setDebugMode() {
|
|
549
|
+
console.warn("setDebugMode is deprecated. use @ledgerhq/logs instead. No logs are emitted in this anymore.");
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Set a timeout (in milliseconds) for the exchange call. Only some transport might implement it. (e.g. U2F)
|
|
553
|
+
*/
|
|
554
|
+
setExchangeTimeout(exchangeTimeout) {
|
|
555
|
+
this.exchangeTimeout = exchangeTimeout;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Define the delay before emitting "unresponsive" on an exchange that does not respond
|
|
559
|
+
*/
|
|
560
|
+
setExchangeUnresponsiveTimeout(unresponsiveTimeout) {
|
|
561
|
+
this.unresponsiveTimeout = unresponsiveTimeout;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* create() allows to open the first descriptor available or
|
|
565
|
+
* throw if there is none or if timeout is reached.
|
|
566
|
+
* This is a light helper, alternative to using listen() and open() (that you may need for any more advanced usecase)
|
|
567
|
+
* @example
|
|
568
|
+
TransportFoo.create().then(transport => ...)
|
|
569
|
+
*/
|
|
570
|
+
static create(openTimeout = 3e3, listenTimeout) {
|
|
571
|
+
return new Promise((resolve, reject) => {
|
|
572
|
+
let found = false;
|
|
573
|
+
const sub = this.listen({
|
|
574
|
+
next: (e) => {
|
|
575
|
+
found = true;
|
|
576
|
+
if (sub)
|
|
577
|
+
sub.unsubscribe();
|
|
578
|
+
if (listenTimeoutId)
|
|
579
|
+
clearTimeout(listenTimeoutId);
|
|
580
|
+
this.open(e.descriptor, openTimeout).then(resolve, reject);
|
|
581
|
+
},
|
|
582
|
+
error: (e) => {
|
|
583
|
+
if (listenTimeoutId)
|
|
584
|
+
clearTimeout(listenTimeoutId);
|
|
585
|
+
reject(e);
|
|
586
|
+
},
|
|
587
|
+
complete: () => {
|
|
588
|
+
if (listenTimeoutId)
|
|
589
|
+
clearTimeout(listenTimeoutId);
|
|
590
|
+
if (!found) {
|
|
591
|
+
reject(new TransportError(this.ErrorMessage_NoDeviceFound, "NoDeviceFound"));
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
const listenTimeoutId = listenTimeout ? setTimeout(() => {
|
|
596
|
+
sub.unsubscribe();
|
|
597
|
+
reject(new TransportError(this.ErrorMessage_ListenTimeout, "ListenTimeout"));
|
|
598
|
+
}, listenTimeout) : null;
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Wrapper to make an exchange "atomic" (blocking any other exchange)
|
|
603
|
+
*
|
|
604
|
+
* It also handles "unresponsiveness" by emitting "unresponsive" and "responsive" events.
|
|
605
|
+
*
|
|
606
|
+
* @param f The exchange job, using the transport to run
|
|
607
|
+
* @returns a Promise resolving with the output of the given job
|
|
608
|
+
*/
|
|
609
|
+
exchangeAtomicImpl(f) {
|
|
610
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
611
|
+
const tracer = this.tracer.withUpdatedContext({
|
|
612
|
+
function: "exchangeAtomicImpl",
|
|
613
|
+
unresponsiveTimeout: this.unresponsiveTimeout
|
|
614
|
+
});
|
|
615
|
+
if (this.exchangeBusyPromise) {
|
|
616
|
+
tracer.trace("Atomic exchange is already busy");
|
|
617
|
+
throw new TransportRaceCondition("An action was already pending on the Ledger device. Please deny or reconnect.");
|
|
618
|
+
}
|
|
619
|
+
let resolveBusy;
|
|
620
|
+
const busyPromise = new Promise((r) => {
|
|
621
|
+
resolveBusy = r;
|
|
622
|
+
});
|
|
623
|
+
this.exchangeBusyPromise = busyPromise;
|
|
624
|
+
let unresponsiveReached = false;
|
|
625
|
+
const timeout = setTimeout(() => {
|
|
626
|
+
tracer.trace(`Timeout reached, emitting Transport event "unresponsive"`, {
|
|
627
|
+
unresponsiveTimeout: this.unresponsiveTimeout
|
|
628
|
+
});
|
|
629
|
+
unresponsiveReached = true;
|
|
630
|
+
this.emit("unresponsive");
|
|
631
|
+
}, this.unresponsiveTimeout);
|
|
632
|
+
try {
|
|
633
|
+
const res = yield f();
|
|
634
|
+
if (unresponsiveReached) {
|
|
635
|
+
tracer.trace("Device was unresponsive, emitting responsive");
|
|
636
|
+
this.emit("responsive");
|
|
637
|
+
}
|
|
638
|
+
return res;
|
|
639
|
+
} finally {
|
|
640
|
+
tracer.trace("Finalize, clearing busy guard");
|
|
641
|
+
clearTimeout(timeout);
|
|
642
|
+
if (resolveBusy)
|
|
643
|
+
resolveBusy();
|
|
644
|
+
this.exchangeBusyPromise = null;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
decorateAppAPIMethods(self, methods, scrambleKey) {
|
|
649
|
+
for (const methodName of methods) {
|
|
650
|
+
self[methodName] = this.decorateAppAPIMethod(methodName, self[methodName], self, scrambleKey);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
decorateAppAPIMethod(methodName, f, ctx, scrambleKey) {
|
|
654
|
+
return (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
655
|
+
const { _appAPIlock } = this;
|
|
656
|
+
if (_appAPIlock) {
|
|
657
|
+
return Promise.reject(new TransportError("Ledger Device is busy (lock " + _appAPIlock + ")", "TransportLocked"));
|
|
658
|
+
}
|
|
659
|
+
try {
|
|
660
|
+
this._appAPIlock = methodName;
|
|
661
|
+
this.setScrambleKey(scrambleKey);
|
|
662
|
+
return yield f.apply(ctx, args);
|
|
663
|
+
} finally {
|
|
664
|
+
this._appAPIlock = null;
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Sets the context used by the logging/tracing mechanism
|
|
670
|
+
*
|
|
671
|
+
* Useful when re-using (cached) the same Transport instance,
|
|
672
|
+
* but with a new tracing context.
|
|
673
|
+
*
|
|
674
|
+
* @param context A TraceContext, that can undefined to reset the context
|
|
675
|
+
*/
|
|
676
|
+
setTraceContext(context) {
|
|
677
|
+
this.tracer = this.tracer.withContext(context);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Updates the context used by the logging/tracing mechanism
|
|
681
|
+
*
|
|
682
|
+
* The update only overrides the key-value that are already defined in the current context.
|
|
683
|
+
*
|
|
684
|
+
* @param contextToAdd A TraceContext that will be added to the current context
|
|
685
|
+
*/
|
|
686
|
+
updateTraceContext(contextToAdd) {
|
|
687
|
+
this.tracer.updateContext(contextToAdd);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Gets the tracing context of the transport instance
|
|
691
|
+
*/
|
|
692
|
+
getTraceContext() {
|
|
693
|
+
return this.tracer.getContext();
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
Transport.ErrorMessage_ListenTimeout = "No Ledger device found (timeout)";
|
|
697
|
+
Transport.ErrorMessage_NoDeviceFound = "No Ledger device found";
|
|
698
|
+
var Transport_default = Transport;
|
|
699
|
+
|
|
700
|
+
// node_modules/.pnpm/@ledgerhq+devices@8.4.4/node_modules/@ledgerhq/devices/lib-es/hid-framing.js
|
|
701
|
+
var Tag = 5;
|
|
702
|
+
function asUInt16BE(value) {
|
|
703
|
+
const b = Buffer.alloc(2);
|
|
704
|
+
b.writeUInt16BE(value, 0);
|
|
705
|
+
return b;
|
|
706
|
+
}
|
|
707
|
+
var initialAcc = {
|
|
708
|
+
data: Buffer.alloc(0),
|
|
709
|
+
dataLength: 0,
|
|
710
|
+
sequence: 0
|
|
711
|
+
};
|
|
712
|
+
var createHIDframing = (channel, packetSize) => {
|
|
713
|
+
return {
|
|
714
|
+
/**
|
|
715
|
+
* Frames/encodes an APDU message into HID USB packets/frames
|
|
716
|
+
*
|
|
717
|
+
* @param apdu The APDU message to send, in a Buffer containing [cla, ins, p1, p2, data length, data(if not empty)]
|
|
718
|
+
* @returns an array of HID USB frames ready to be sent
|
|
719
|
+
*/
|
|
720
|
+
makeBlocks(apdu) {
|
|
721
|
+
let data = Buffer.concat([asUInt16BE(apdu.length), apdu]);
|
|
722
|
+
const blockSize = packetSize - 5;
|
|
723
|
+
const nbBlocks = Math.ceil(data.length / blockSize);
|
|
724
|
+
data = Buffer.concat([data, Buffer.alloc(nbBlocks * blockSize - data.length + 1).fill(0)]);
|
|
725
|
+
const blocks = [];
|
|
726
|
+
for (let i = 0; i < nbBlocks; i++) {
|
|
727
|
+
const head = Buffer.alloc(5);
|
|
728
|
+
head.writeUInt16BE(channel, 0);
|
|
729
|
+
head.writeUInt8(Tag, 2);
|
|
730
|
+
head.writeUInt16BE(i, 3);
|
|
731
|
+
const chunk = data.slice(i * blockSize, (i + 1) * blockSize);
|
|
732
|
+
blocks.push(Buffer.concat([head, chunk]));
|
|
733
|
+
}
|
|
734
|
+
return blocks;
|
|
735
|
+
},
|
|
736
|
+
/**
|
|
737
|
+
* Reduces HID USB packets/frames to one response.
|
|
738
|
+
*
|
|
739
|
+
* @param acc The value resulting from (accumulating) the previous call of reduceResponse.
|
|
740
|
+
* On first call initialized to `initialAcc`. The accumulator enables handling multi-frames messages.
|
|
741
|
+
* @param chunk Current chunk to reduce into accumulator
|
|
742
|
+
* @returns An accumulator value updated with the current chunk
|
|
743
|
+
*/
|
|
744
|
+
reduceResponse(acc, chunk) {
|
|
745
|
+
let { data, dataLength, sequence } = acc || initialAcc;
|
|
746
|
+
if (chunk.readUInt16BE(0) !== channel) {
|
|
747
|
+
throw new TransportError("Invalid channel", "InvalidChannel");
|
|
748
|
+
}
|
|
749
|
+
if (chunk.readUInt8(2) !== Tag) {
|
|
750
|
+
throw new TransportError("Invalid tag", "InvalidTag");
|
|
751
|
+
}
|
|
752
|
+
if (chunk.readUInt16BE(3) !== sequence) {
|
|
753
|
+
throw new TransportError("Invalid sequence", "InvalidSequence");
|
|
754
|
+
}
|
|
755
|
+
if (!acc) {
|
|
756
|
+
dataLength = chunk.readUInt16BE(5);
|
|
757
|
+
}
|
|
758
|
+
sequence++;
|
|
759
|
+
const chunkData = chunk.slice(acc ? 5 : 7);
|
|
760
|
+
data = Buffer.concat([data, chunkData]);
|
|
761
|
+
if (data.length > dataLength) {
|
|
762
|
+
data = data.slice(0, dataLength);
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
data,
|
|
766
|
+
dataLength,
|
|
767
|
+
sequence
|
|
768
|
+
};
|
|
769
|
+
},
|
|
770
|
+
/**
|
|
771
|
+
* Returns the response message that has been reduced from the HID USB frames
|
|
772
|
+
*
|
|
773
|
+
* @param acc The accumulator
|
|
774
|
+
* @returns A Buffer containing the cleaned response message, or null if no response message, or undefined if the
|
|
775
|
+
* accumulator is incorrect (message length is not valid)
|
|
776
|
+
*/
|
|
777
|
+
getReducedResult(acc) {
|
|
778
|
+
if (acc && acc.dataLength === acc.data.length) {
|
|
779
|
+
return acc.data;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
};
|
|
784
|
+
var hid_framing_default = createHIDframing;
|
|
785
|
+
|
|
786
|
+
// node_modules/.pnpm/@ledgerhq+devices@8.4.4/node_modules/@ledgerhq/devices/lib-es/index.js
|
|
787
|
+
var import_semver = __toESM(require_semver());
|
|
788
|
+
var DeviceModelId;
|
|
789
|
+
(function(DeviceModelId2) {
|
|
790
|
+
DeviceModelId2["blue"] = "blue";
|
|
791
|
+
DeviceModelId2["nanoS"] = "nanoS";
|
|
792
|
+
DeviceModelId2["nanoSP"] = "nanoSP";
|
|
793
|
+
DeviceModelId2["nanoX"] = "nanoX";
|
|
794
|
+
DeviceModelId2["stax"] = "stax";
|
|
795
|
+
DeviceModelId2["europa"] = "europa";
|
|
796
|
+
})(DeviceModelId || (DeviceModelId = {}));
|
|
797
|
+
var devices = {
|
|
798
|
+
[DeviceModelId.blue]: {
|
|
799
|
+
id: DeviceModelId.blue,
|
|
800
|
+
productName: "Ledger\xA0Blue",
|
|
801
|
+
productIdMM: 0,
|
|
802
|
+
legacyUsbProductId: 0,
|
|
803
|
+
usbOnly: true,
|
|
804
|
+
memorySize: 480 * 1024,
|
|
805
|
+
masks: [822083584, 822149120],
|
|
806
|
+
getBlockSize: (_firwareVersion) => 4 * 1024
|
|
807
|
+
},
|
|
808
|
+
[DeviceModelId.nanoS]: {
|
|
809
|
+
id: DeviceModelId.nanoS,
|
|
810
|
+
productName: "Ledger\xA0Nano\xA0S",
|
|
811
|
+
productIdMM: 16,
|
|
812
|
+
legacyUsbProductId: 1,
|
|
813
|
+
usbOnly: true,
|
|
814
|
+
memorySize: 320 * 1024,
|
|
815
|
+
masks: [823132160],
|
|
816
|
+
getBlockSize: (firmwareVersion) => {
|
|
817
|
+
var _a;
|
|
818
|
+
return import_semver.default.lt((_a = import_semver.default.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0") ? 4 * 1024 : 2 * 1024;
|
|
819
|
+
}
|
|
820
|
+
},
|
|
821
|
+
[DeviceModelId.nanoX]: {
|
|
822
|
+
id: DeviceModelId.nanoX,
|
|
823
|
+
productName: "Ledger\xA0Nano\xA0X",
|
|
824
|
+
productIdMM: 64,
|
|
825
|
+
legacyUsbProductId: 4,
|
|
826
|
+
usbOnly: false,
|
|
827
|
+
memorySize: 2 * 1024 * 1024,
|
|
828
|
+
masks: [855638016],
|
|
829
|
+
getBlockSize: (_firwareVersion) => 4 * 1024,
|
|
830
|
+
bluetoothSpec: [
|
|
831
|
+
{
|
|
832
|
+
serviceUuid: "13d63400-2c97-0004-0000-4c6564676572",
|
|
833
|
+
notifyUuid: "13d63400-2c97-0004-0001-4c6564676572",
|
|
834
|
+
writeUuid: "13d63400-2c97-0004-0002-4c6564676572",
|
|
835
|
+
writeCmdUuid: "13d63400-2c97-0004-0003-4c6564676572"
|
|
836
|
+
}
|
|
837
|
+
]
|
|
838
|
+
},
|
|
839
|
+
[DeviceModelId.nanoSP]: {
|
|
840
|
+
id: DeviceModelId.nanoSP,
|
|
841
|
+
productName: "Ledger Nano S Plus",
|
|
842
|
+
productIdMM: 80,
|
|
843
|
+
legacyUsbProductId: 5,
|
|
844
|
+
usbOnly: true,
|
|
845
|
+
memorySize: 1533 * 1024,
|
|
846
|
+
masks: [856686592],
|
|
847
|
+
getBlockSize: (_firmwareVersion) => 32
|
|
848
|
+
},
|
|
849
|
+
[DeviceModelId.stax]: {
|
|
850
|
+
id: DeviceModelId.stax,
|
|
851
|
+
productName: "Ledger\xA0Stax",
|
|
852
|
+
productIdMM: 96,
|
|
853
|
+
legacyUsbProductId: 6,
|
|
854
|
+
usbOnly: false,
|
|
855
|
+
memorySize: 1533 * 1024,
|
|
856
|
+
masks: [857735168],
|
|
857
|
+
getBlockSize: (_firmwareVersion) => 32,
|
|
858
|
+
bluetoothSpec: [
|
|
859
|
+
{
|
|
860
|
+
serviceUuid: "13d63400-2c97-6004-0000-4c6564676572",
|
|
861
|
+
notifyUuid: "13d63400-2c97-6004-0001-4c6564676572",
|
|
862
|
+
writeUuid: "13d63400-2c97-6004-0002-4c6564676572",
|
|
863
|
+
writeCmdUuid: "13d63400-2c97-6004-0003-4c6564676572"
|
|
864
|
+
}
|
|
865
|
+
]
|
|
866
|
+
},
|
|
867
|
+
[DeviceModelId.europa]: {
|
|
868
|
+
id: DeviceModelId.europa,
|
|
869
|
+
productName: "Ledger\xA0Flex",
|
|
870
|
+
productIdMM: 112,
|
|
871
|
+
legacyUsbProductId: 7,
|
|
872
|
+
usbOnly: false,
|
|
873
|
+
memorySize: 1533 * 1024,
|
|
874
|
+
masks: [858783744],
|
|
875
|
+
getBlockSize: (_firmwareVersion) => 32,
|
|
876
|
+
bluetoothSpec: [
|
|
877
|
+
{
|
|
878
|
+
serviceUuid: "13d63400-2c97-3004-0000-4c6564676572",
|
|
879
|
+
notifyUuid: "13d63400-2c97-3004-0001-4c6564676572",
|
|
880
|
+
writeUuid: "13d63400-2c97-3004-0002-4c6564676572",
|
|
881
|
+
writeCmdUuid: "13d63400-2c97-3004-0003-4c6564676572"
|
|
882
|
+
}
|
|
883
|
+
]
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
var productMap = {
|
|
887
|
+
Blue: DeviceModelId.blue,
|
|
888
|
+
"Nano S": DeviceModelId.nanoS,
|
|
889
|
+
"Nano S Plus": DeviceModelId.nanoSP,
|
|
890
|
+
"Nano X": DeviceModelId.nanoX,
|
|
891
|
+
Stax: DeviceModelId.stax,
|
|
892
|
+
Europa: DeviceModelId.europa
|
|
893
|
+
};
|
|
894
|
+
var devicesList = Object.values(devices);
|
|
895
|
+
var ledgerUSBVendorId = 11415;
|
|
896
|
+
var identifyUSBProductId = (usbProductId) => {
|
|
897
|
+
const legacy = devicesList.find((d) => d.legacyUsbProductId === usbProductId);
|
|
898
|
+
if (legacy)
|
|
899
|
+
return legacy;
|
|
900
|
+
const mm = usbProductId >> 8;
|
|
901
|
+
const deviceModel = devicesList.find((d) => d.productIdMM === mm);
|
|
902
|
+
return deviceModel;
|
|
903
|
+
};
|
|
904
|
+
var bluetoothServices = [];
|
|
905
|
+
var serviceUuidToInfos = {};
|
|
906
|
+
for (const id2 in devices) {
|
|
907
|
+
const deviceModel = devices[id2];
|
|
908
|
+
const { bluetoothSpec } = deviceModel;
|
|
909
|
+
if (bluetoothSpec) {
|
|
910
|
+
for (let i = 0; i < bluetoothSpec.length; i++) {
|
|
911
|
+
const spec = bluetoothSpec[i];
|
|
912
|
+
bluetoothServices.push(spec.serviceUuid);
|
|
913
|
+
serviceUuidToInfos[spec.serviceUuid] = serviceUuidToInfos[spec.serviceUuid.replace(/-/g, "")] = Object.assign({ deviceModel }, spec);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
export {
|
|
919
|
+
DisconnectedDevice,
|
|
920
|
+
DisconnectedDeviceDuringOperation,
|
|
921
|
+
TransportOpenUserCancelled,
|
|
922
|
+
TransportInterfaceNotAvailable,
|
|
923
|
+
TransportWebUSBGestureRequired,
|
|
924
|
+
TransportError,
|
|
925
|
+
log,
|
|
926
|
+
Transport_default,
|
|
927
|
+
hid_framing_default,
|
|
928
|
+
ledgerUSBVendorId,
|
|
929
|
+
identifyUSBProductId
|
|
930
|
+
};
|