@shapeshiftoss/hdwallet-keepkey 1.62.41 → 1.62.42

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.
Files changed (114) hide show
  1. package/LICENSE.md +6 -6
  2. package/dist/cjs/.tsbuildinfo +1 -0
  3. package/dist/{adapter.d.ts → cjs/adapter.d.ts} +6 -7
  4. package/dist/cjs/adapter.js +146 -0
  5. package/dist/{binance.d.ts → cjs/binance.d.ts} +3 -4
  6. package/dist/cjs/binance.js +144 -0
  7. package/dist/{bitcoin.d.ts → cjs/bitcoin.d.ts} +3 -4
  8. package/dist/cjs/bitcoin.js +549 -0
  9. package/dist/{bnbencoding.d.ts → cjs/bnbencoding.d.ts} +3 -2
  10. package/dist/{bnbencoding.js → cjs/bnbencoding.js} +22 -22
  11. package/dist/{cosmos.d.ts → cjs/cosmos.d.ts} +4 -5
  12. package/dist/cjs/cosmos.js +219 -0
  13. package/dist/{eos.d.ts → cjs/eos.d.ts} +3 -4
  14. package/dist/cjs/eos.js +244 -0
  15. package/dist/{ethereum.d.ts → cjs/ethereum.d.ts} +4 -5
  16. package/dist/cjs/ethereum.js +264 -0
  17. package/dist/cjs/index.d.ts +5 -0
  18. package/dist/{index.js → cjs/index.js} +0 -1
  19. package/dist/{keepkey.d.ts → cjs/keepkey.d.ts} +45 -20
  20. package/dist/cjs/keepkey.js +959 -0
  21. package/dist/{mayachain.d.ts → cjs/mayachain.d.ts} +4 -5
  22. package/dist/cjs/mayachain.js +169 -0
  23. package/dist/{osmosis.d.ts → cjs/osmosis.d.ts} +4 -5
  24. package/dist/cjs/osmosis.js +270 -0
  25. package/dist/cjs/package.json +1 -0
  26. package/dist/{ripple.d.ts → cjs/ripple.d.ts} +3 -4
  27. package/dist/cjs/ripple.js +104 -0
  28. package/dist/{thorchain.d.ts → cjs/thorchain.d.ts} +4 -5
  29. package/dist/cjs/thorchain.js +169 -0
  30. package/dist/{transport.d.ts → cjs/transport.d.ts} +2 -3
  31. package/dist/cjs/transport.js +333 -0
  32. package/dist/{typeRegistry.d.ts → cjs/typeRegistry.d.ts} +2 -3
  33. package/dist/{typeRegistry.js → cjs/typeRegistry.js} +26 -13
  34. package/dist/{utils.d.ts → cjs/utils.d.ts} +1 -2
  35. package/dist/{utils.js → cjs/utils.js} +7 -8
  36. package/dist/esm/.tsbuildinfo +1 -0
  37. package/dist/esm/adapter.d.ts +35 -0
  38. package/dist/esm/adapter.js +119 -0
  39. package/dist/esm/binance.d.ts +5 -0
  40. package/dist/esm/binance.js +112 -0
  41. package/dist/esm/bitcoin.d.ts +11 -0
  42. package/dist/esm/bitcoin.js +511 -0
  43. package/dist/esm/bnbencoding.d.ts +11 -0
  44. package/dist/esm/bnbencoding.js +103 -0
  45. package/dist/esm/cosmos.d.ts +6 -0
  46. package/dist/esm/cosmos.js +187 -0
  47. package/dist/esm/eos.d.ts +5 -0
  48. package/dist/esm/eos.js +212 -0
  49. package/dist/esm/ethereum.d.ts +17 -0
  50. package/dist/esm/ethereum.js +229 -0
  51. package/dist/esm/index.d.ts +5 -0
  52. package/dist/esm/index.js +5 -0
  53. package/dist/esm/keepkey.d.ts +177 -0
  54. package/dist/esm/keepkey.js +925 -0
  55. package/dist/esm/mayachain.d.ts +6 -0
  56. package/dist/esm/mayachain.js +137 -0
  57. package/dist/esm/osmosis.d.ts +6 -0
  58. package/dist/esm/osmosis.js +238 -0
  59. package/dist/esm/ripple.d.ts +5 -0
  60. package/dist/esm/ripple.js +72 -0
  61. package/dist/esm/thorchain.d.ts +6 -0
  62. package/dist/esm/thorchain.js +137 -0
  63. package/dist/esm/transport.d.ts +55 -0
  64. package/dist/esm/transport.js +306 -0
  65. package/dist/esm/typeRegistry.d.ts +4 -0
  66. package/dist/esm/typeRegistry.js +47 -0
  67. package/dist/esm/utils.d.ts +6 -0
  68. package/dist/esm/utils.js +56 -0
  69. package/package.json +33 -19
  70. package/dist/adapter.d.ts.map +0 -1
  71. package/dist/adapter.js +0 -175
  72. package/dist/adapter.js.map +0 -1
  73. package/dist/binance.d.ts.map +0 -1
  74. package/dist/binance.js +0 -146
  75. package/dist/binance.js.map +0 -1
  76. package/dist/bitcoin.d.ts.map +0 -1
  77. package/dist/bitcoin.js +0 -568
  78. package/dist/bitcoin.js.map +0 -1
  79. package/dist/bnbencoding.d.ts.map +0 -1
  80. package/dist/bnbencoding.js.map +0 -1
  81. package/dist/cosmos.d.ts.map +0 -1
  82. package/dist/cosmos.js +0 -230
  83. package/dist/cosmos.js.map +0 -1
  84. package/dist/eos.d.ts.map +0 -1
  85. package/dist/eos.js +0 -247
  86. package/dist/eos.js.map +0 -1
  87. package/dist/ethereum.d.ts.map +0 -1
  88. package/dist/ethereum.js +0 -281
  89. package/dist/ethereum.js.map +0 -1
  90. package/dist/index.d.ts +0 -6
  91. package/dist/index.d.ts.map +0 -1
  92. package/dist/index.js.map +0 -1
  93. package/dist/keepkey.d.ts.map +0 -1
  94. package/dist/keepkey.js +0 -1027
  95. package/dist/keepkey.js.map +0 -1
  96. package/dist/mayachain.d.ts.map +0 -1
  97. package/dist/mayachain.js +0 -180
  98. package/dist/mayachain.js.map +0 -1
  99. package/dist/osmosis.d.ts.map +0 -1
  100. package/dist/osmosis.js +0 -278
  101. package/dist/osmosis.js.map +0 -1
  102. package/dist/ripple.d.ts.map +0 -1
  103. package/dist/ripple.js +0 -111
  104. package/dist/ripple.js.map +0 -1
  105. package/dist/thorchain.d.ts.map +0 -1
  106. package/dist/thorchain.js +0 -180
  107. package/dist/thorchain.js.map +0 -1
  108. package/dist/transport.d.ts.map +0 -1
  109. package/dist/transport.js +0 -365
  110. package/dist/transport.js.map +0 -1
  111. package/dist/typeRegistry.d.ts.map +0 -1
  112. package/dist/typeRegistry.js.map +0 -1
  113. package/dist/utils.d.ts.map +0 -1
  114. package/dist/utils.js.map +0 -1
@@ -0,0 +1,959 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.create = exports.info = exports.KeepKeyHDWallet = exports.KeepKeyHDWalletInfo = exports.isKeepKey = void 0;
30
+ const Messages = __importStar(require("@keepkey/device-protocol/lib/messages_pb"));
31
+ const Types = __importStar(require("@keepkey/device-protocol/lib/types_pb"));
32
+ const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
33
+ const isObject_1 = __importDefault(require("lodash/isObject"));
34
+ const semver_1 = __importDefault(require("semver"));
35
+ const Binance = __importStar(require("./binance"));
36
+ const Btc = __importStar(require("./bitcoin"));
37
+ const Cosmos = __importStar(require("./cosmos"));
38
+ const Eos = __importStar(require("./eos"));
39
+ const Eth = __importStar(require("./ethereum"));
40
+ const Mayachain = __importStar(require("./mayachain"));
41
+ const Osmosis = __importStar(require("./osmosis"));
42
+ const Ripple = __importStar(require("./ripple"));
43
+ const Thorchain = __importStar(require("./thorchain"));
44
+ const typeRegistry_1 = require("./typeRegistry");
45
+ const utils_1 = require("./utils");
46
+ function isKeepKey(wallet) {
47
+ return (0, isObject_1.default)(wallet) && wallet._isKeepKey;
48
+ }
49
+ exports.isKeepKey = isKeepKey;
50
+ function describeUTXOPath(path, coin, scriptType) {
51
+ const pathStr = core.addressNListToBIP32(path);
52
+ const unknown = {
53
+ verbose: pathStr,
54
+ coin,
55
+ scriptType,
56
+ isKnown: false,
57
+ };
58
+ if (!scriptType)
59
+ return unknown;
60
+ if (!Btc.btcSupportsCoin(coin))
61
+ return unknown;
62
+ if (!Btc.btcSupportsScriptType(coin, scriptType))
63
+ return unknown;
64
+ if (path.length !== 3 && path.length !== 5)
65
+ return unknown;
66
+ if ((path[0] & 0x80000000) >>> 0 !== 0x80000000)
67
+ return unknown;
68
+ const purpose = path[0] & 0x7fffffff;
69
+ if (![44, 49, 84].includes(purpose))
70
+ return unknown;
71
+ if (purpose === 44 && scriptType !== core.BTCInputScriptType.SpendAddress)
72
+ return unknown;
73
+ if (purpose === 49 && scriptType !== core.BTCInputScriptType.SpendP2SHWitness)
74
+ return unknown;
75
+ if (purpose === 84 && scriptType !== core.BTCInputScriptType.SpendWitness)
76
+ return unknown;
77
+ const wholeAccount = path.length === 3;
78
+ const script = scriptType
79
+ ? {
80
+ [core.BTCInputScriptType.SpendAddress]: ['Legacy'],
81
+ [core.BTCInputScriptType.SpendP2SHWitness]: [],
82
+ [core.BTCInputScriptType.SpendWitness]: ['Segwit Native'],
83
+ }[scriptType] ?? []
84
+ : [];
85
+ let isPrefork = false;
86
+ const slip44 = core.slip44ByCoin(coin);
87
+ if (slip44 === undefined)
88
+ return unknown;
89
+ if (path[1] !== 0x80000000 + slip44) {
90
+ switch (coin) {
91
+ case 'BitcoinCash':
92
+ case 'BitcoinGold': {
93
+ if (path[1] === 0x80000000 + core.slip44ByCoin('Bitcoin')) {
94
+ isPrefork = true;
95
+ break;
96
+ }
97
+ return unknown;
98
+ }
99
+ case 'BitcoinSV': {
100
+ if (path[1] === 0x80000000 + core.slip44ByCoin('Bitcoin') ||
101
+ path[1] === 0x80000000 + core.slip44ByCoin('BitcoinCash')) {
102
+ isPrefork = true;
103
+ break;
104
+ }
105
+ return unknown;
106
+ }
107
+ default:
108
+ return unknown;
109
+ }
110
+ }
111
+ let attributes = isPrefork ? ['Prefork'] : [];
112
+ switch (coin) {
113
+ case 'Bitcoin':
114
+ case 'Litecoin':
115
+ case 'BitcoinGold':
116
+ case 'Testnet': {
117
+ attributes = attributes.concat(script);
118
+ break;
119
+ }
120
+ default:
121
+ break;
122
+ }
123
+ const attr = attributes.length ? ` (${attributes.join(', ')})` : '';
124
+ const accountIdx = path[2] & 0x7fffffff;
125
+ if (wholeAccount) {
126
+ return {
127
+ coin,
128
+ verbose: `${coin} Account #${accountIdx}${attr}`,
129
+ accountIdx,
130
+ wholeAccount: true,
131
+ isKnown: true,
132
+ scriptType,
133
+ isPrefork,
134
+ };
135
+ }
136
+ else {
137
+ const change = path[3] === 1 ? 'Change ' : '';
138
+ const addressIdx = path[4];
139
+ return {
140
+ coin,
141
+ verbose: `${coin} Account #${accountIdx}, ${change}Address #${addressIdx}${attr}`,
142
+ accountIdx,
143
+ addressIdx,
144
+ wholeAccount: false,
145
+ isKnown: true,
146
+ isChange: path[3] === 1,
147
+ scriptType,
148
+ isPrefork,
149
+ };
150
+ }
151
+ }
152
+ function describeEosPath(path) {
153
+ const pathStr = core.addressNListToBIP32(path);
154
+ const unknown = {
155
+ verbose: pathStr,
156
+ coin: 'Eos',
157
+ isKnown: false,
158
+ };
159
+ if (path.length != 5) {
160
+ return unknown;
161
+ }
162
+ if (path[0] != 0x80000000 + 44) {
163
+ return unknown;
164
+ }
165
+ if (path[1] != 0x80000000 + core.slip44ByCoin('Eos')) {
166
+ return unknown;
167
+ }
168
+ if ((path[2] & 0x80000000) >>> 0 !== 0x80000000) {
169
+ return unknown;
170
+ }
171
+ if (path[3] !== 0 || path[4] !== 0) {
172
+ return unknown;
173
+ }
174
+ const index = path[2] & 0x7fffffff;
175
+ return {
176
+ verbose: `Eos Account #${index}`,
177
+ accountIdx: index,
178
+ wholeAccount: true,
179
+ coin: 'Eos',
180
+ isKnown: true,
181
+ isPrefork: false,
182
+ };
183
+ }
184
+ function describeRipplePath(path) {
185
+ const pathStr = core.addressNListToBIP32(path);
186
+ const unknown = {
187
+ verbose: pathStr,
188
+ coin: 'Ripple',
189
+ isKnown: false,
190
+ };
191
+ if (path.length != 5) {
192
+ return unknown;
193
+ }
194
+ if (path[0] != 0x80000000 + 44) {
195
+ return unknown;
196
+ }
197
+ if (path[1] != 0x80000000 + core.slip44ByCoin('Ripple')) {
198
+ return unknown;
199
+ }
200
+ if ((path[2] & 0x80000000) >>> 0 !== 0x80000000) {
201
+ return unknown;
202
+ }
203
+ if (path[3] !== 0 || path[4] !== 0) {
204
+ return unknown;
205
+ }
206
+ const index = path[2] & 0x7fffffff;
207
+ return {
208
+ verbose: `Ripple Account #${index}`,
209
+ accountIdx: index,
210
+ wholeAccount: true,
211
+ coin: 'Ripple',
212
+ isKnown: true,
213
+ isPrefork: false,
214
+ };
215
+ }
216
+ class KeepKeyHDWalletInfo {
217
+ _supportsBTCInfo = true;
218
+ _supportsETHInfo = true;
219
+ _supportsCosmosInfo = true;
220
+ _supportsOsmosisInfo = true;
221
+ _supportsRippleInfo = true;
222
+ _supportsBinanceInfo = true;
223
+ _supportsEosInfo = true;
224
+ _supportsThorchainInfo = true;
225
+ _supportsMayachainInfo = true;
226
+ getVendor() {
227
+ return 'KeepKey';
228
+ }
229
+ async btcSupportsCoin(coin) {
230
+ return Btc.btcSupportsCoin(coin);
231
+ }
232
+ async btcSupportsScriptType(coin, scriptType) {
233
+ return Btc.btcSupportsScriptType(coin, scriptType);
234
+ }
235
+ async btcSupportsSecureTransfer() {
236
+ return Btc.btcSupportsSecureTransfer();
237
+ }
238
+ btcSupportsNativeShapeShift() {
239
+ return Btc.btcSupportsNativeShapeShift();
240
+ }
241
+ btcGetAccountPaths(msg) {
242
+ return Btc.btcGetAccountPaths(msg);
243
+ }
244
+ async ethSupportsNetwork(chain_id) {
245
+ return Eth.ethSupportsNetwork(chain_id);
246
+ }
247
+ async ethSupportsSecureTransfer() {
248
+ return Eth.ethSupportsSecureTransfer();
249
+ }
250
+ ethSupportsNativeShapeShift() {
251
+ return Eth.ethSupportsNativeShapeShift();
252
+ }
253
+ async ethSupportsEIP1559() {
254
+ // EIP1559 support starts in v7.2.1
255
+ // return semver.gte(await this.getFirmwareVersion(), "v7.2.1");
256
+ // disable EIP1559 support until edge case fail states are fixed across all evm chains
257
+ return false;
258
+ }
259
+ ethGetAccountPaths(msg) {
260
+ return Eth.ethGetAccountPaths(msg);
261
+ }
262
+ cosmosGetAccountPaths(msg) {
263
+ return Cosmos.cosmosGetAccountPaths(msg);
264
+ }
265
+ osmosisGetAccountPaths(msg) {
266
+ return Osmosis.osmosisGetAccountPaths(msg);
267
+ }
268
+ thorchainGetAccountPaths(msg) {
269
+ return Thorchain.thorchainGetAccountPaths(msg);
270
+ }
271
+ mayachainGetAccountPaths(msg) {
272
+ return Mayachain.mayachainGetAccountPaths(msg);
273
+ }
274
+ rippleGetAccountPaths(msg) {
275
+ return Ripple.rippleGetAccountPaths(msg);
276
+ }
277
+ binanceGetAccountPaths(msg) {
278
+ return Binance.binanceGetAccountPaths(msg);
279
+ }
280
+ eosGetAccountPaths(msg) {
281
+ return Eos.eosGetAccountPaths(msg);
282
+ }
283
+ hasOnDevicePinEntry() {
284
+ return false;
285
+ }
286
+ hasOnDevicePassphrase() {
287
+ return false;
288
+ }
289
+ hasOnDeviceDisplay() {
290
+ return true;
291
+ }
292
+ hasOnDeviceRecovery() {
293
+ return false;
294
+ }
295
+ hasNativeShapeShift(_srcCoin, _dstCoin) {
296
+ return true;
297
+ }
298
+ supportsBip44Accounts() {
299
+ return true;
300
+ }
301
+ supportsOfflineSigning() {
302
+ return true;
303
+ }
304
+ supportsBroadcast() {
305
+ return false;
306
+ }
307
+ describePath(msg) {
308
+ switch (msg.coin) {
309
+ case 'Ethereum':
310
+ return core.describeETHPath(msg.path);
311
+ case 'Atom':
312
+ return core.cosmosDescribePath(msg.path);
313
+ case 'Osmo':
314
+ return core.osmosisDescribePath(msg.path);
315
+ case 'Binance':
316
+ return core.binanceDescribePath(msg.path);
317
+ case 'Ripple':
318
+ return describeRipplePath(msg.path);
319
+ case 'Eos':
320
+ return describeEosPath(msg.path);
321
+ case 'Thorchain':
322
+ return core.thorchainDescribePath(msg.path);
323
+ case 'Mayachain':
324
+ return core.mayachainDescribePath(msg.path);
325
+ default:
326
+ return describeUTXOPath(msg.path, msg.coin, msg.scriptType);
327
+ }
328
+ }
329
+ btcNextAccountPath(msg) {
330
+ const description = describeUTXOPath(msg.addressNList, msg.coin, msg.scriptType);
331
+ if (!description.isKnown) {
332
+ return undefined;
333
+ }
334
+ const addressNList = msg.addressNList;
335
+ if (addressNList[0] === 0x80000000 + 44 ||
336
+ addressNList[0] === 0x80000000 + 49 ||
337
+ addressNList[0] === 0x80000000 + 84) {
338
+ addressNList[2] += 1;
339
+ return {
340
+ ...msg,
341
+ addressNList,
342
+ };
343
+ }
344
+ return undefined;
345
+ }
346
+ ethNextAccountPath(msg) {
347
+ const addressNList = msg.hardenedPath.concat(msg.relPath);
348
+ const description = core.describeETHPath(addressNList);
349
+ if (!description.isKnown) {
350
+ return undefined;
351
+ }
352
+ if (addressNList[0] === 0x80000000 + 44) {
353
+ addressNList[2] += 1;
354
+ return {
355
+ ...msg,
356
+ addressNList,
357
+ hardenedPath: core.hardenedPath(addressNList),
358
+ relPath: core.relativePath(addressNList),
359
+ };
360
+ }
361
+ return undefined;
362
+ }
363
+ cosmosNextAccountPath(msg) {
364
+ const description = core.cosmosDescribePath(msg.addressNList);
365
+ if (!description.isKnown) {
366
+ return undefined;
367
+ }
368
+ const addressNList = msg.addressNList;
369
+ addressNList[2] += 1;
370
+ return {
371
+ ...msg,
372
+ addressNList,
373
+ };
374
+ }
375
+ osmosisNextAccountPath(msg) {
376
+ const description = core.osmosisDescribePath(msg.addressNList);
377
+ if (!description.isKnown) {
378
+ return undefined;
379
+ }
380
+ const addressNList = msg.addressNList;
381
+ addressNList[2] += 1;
382
+ return {
383
+ ...msg,
384
+ addressNList,
385
+ };
386
+ }
387
+ thorchainNextAccountPath(msg) {
388
+ const description = core.thorchainDescribePath(msg.addressNList);
389
+ if (!description.isKnown)
390
+ return undefined;
391
+ const addressNList = msg.addressNList;
392
+ addressNList[2] += 1;
393
+ return {
394
+ ...msg,
395
+ addressNList,
396
+ };
397
+ }
398
+ mayachainNextAccountPath(msg) {
399
+ const description = core.mayachainDescribePath(msg.addressNList);
400
+ if (!description.isKnown)
401
+ return undefined;
402
+ const addressNList = msg.addressNList;
403
+ addressNList[2] += 1;
404
+ return {
405
+ ...msg,
406
+ addressNList,
407
+ };
408
+ }
409
+ rippleNextAccountPath(msg) {
410
+ const description = describeRipplePath(msg.addressNList);
411
+ if (!description.isKnown) {
412
+ return undefined;
413
+ }
414
+ const addressNList = msg.addressNList;
415
+ addressNList[2] += 1;
416
+ return {
417
+ ...msg,
418
+ addressNList,
419
+ };
420
+ }
421
+ binanceNextAccountPath(msg) {
422
+ const description = core.binanceDescribePath(msg.addressNList);
423
+ if (!description.isKnown) {
424
+ return undefined;
425
+ }
426
+ const addressNList = msg.addressNList;
427
+ addressNList[2] += 1;
428
+ return {
429
+ ...msg,
430
+ addressNList,
431
+ };
432
+ }
433
+ eosNextAccountPath(msg) {
434
+ const description = describeEosPath(msg.addressNList);
435
+ if (!description.isKnown) {
436
+ return undefined;
437
+ }
438
+ const addressNList = msg.addressNList;
439
+ addressNList[2] += 1;
440
+ return {
441
+ ...msg,
442
+ addressNList,
443
+ };
444
+ }
445
+ }
446
+ exports.KeepKeyHDWalletInfo = KeepKeyHDWalletInfo;
447
+ class KeepKeyHDWallet extends KeepKeyHDWalletInfo {
448
+ _supportsDebugLink;
449
+ _isKeepKey = true;
450
+ _supportsETH = true;
451
+ _supportsEthSwitchChain = false;
452
+ _supportsAvalanche = false;
453
+ _supportsOptimism = true;
454
+ _supportsBSC = true;
455
+ _supportsPolygon = true;
456
+ _supportsGnosis = true;
457
+ _supportsArbitrum = true;
458
+ _supportsArbitrumNova = false;
459
+ _supportsBase = true;
460
+ _supportsMonad = false;
461
+ _supportsPlasma = false;
462
+ _supportsPlume = false;
463
+ _supportsKatana = false;
464
+ _supportsEthereal = false;
465
+ _supportsStory = false;
466
+ _supportsSonic = false;
467
+ _supportsBob = false;
468
+ _supportsMode = false;
469
+ _supportsSei = false;
470
+ _supportsHyperEvm = false;
471
+ _supportsMantle = false;
472
+ _supportsInk = false;
473
+ _supportsMegaEth = false;
474
+ _supportsZkSyncEra = false;
475
+ _supportsBlast = false;
476
+ _supportsAbstract = false;
477
+ _supportsWorldChain = false;
478
+ _supportsHemi = false;
479
+ _supportsFlowEvm = false;
480
+ _supportsCelo = false;
481
+ _supportsBerachain = false;
482
+ _supportsLinea = false;
483
+ _supportsScroll = false;
484
+ _supportsCronos = false;
485
+ _supportsUnichain = false;
486
+ _supportsSoneium = false;
487
+ _supportsRobinhood = false;
488
+ _supportsBTC = true;
489
+ _supportsCosmos = true;
490
+ _supportsOsmosis = true;
491
+ _supportsRipple = true;
492
+ _supportsBinance = true;
493
+ _supportsEos = true;
494
+ _supportsThorchain = true;
495
+ _supportsMayachain = true;
496
+ transport;
497
+ features;
498
+ info;
499
+ featuresCache;
500
+ constructor(transport) {
501
+ super();
502
+ this.transport = transport;
503
+ this._supportsDebugLink = transport.debugLink;
504
+ this.info = new KeepKeyHDWalletInfo();
505
+ }
506
+ static async create(transport) {
507
+ return new KeepKeyHDWallet(transport);
508
+ }
509
+ async getDeviceID() {
510
+ const featuresId = (await this.getFeatures(/*cached=*/ true)).deviceId;
511
+ // Devices in bootloader mode show up with empty string deviceId's in their features object.
512
+ if (featuresId)
513
+ return featuresId;
514
+ // Grabbing the one from the transport seems to be a reasonable fallback.
515
+ return await this.transport.getDeviceID();
516
+ }
517
+ async getModel() {
518
+ return core.mustBeDefined((await this.getFeatures(/*cached=*/ true)).model);
519
+ }
520
+ async getFirmwareVersion() {
521
+ const features = await this.getFeatures(/*cached=*/ true);
522
+ return `v${features.majorVersion}.${features.minorVersion}.${features.patchVersion}`;
523
+ }
524
+ async getLabel() {
525
+ return (await this.getFeatures(/*cached=*/ true)).label ?? '';
526
+ }
527
+ async isInitialized() {
528
+ return !!(await this.getFeatures()).initialized;
529
+ }
530
+ async isLocked() {
531
+ const features = await this.getFeatures();
532
+ if (features.pinProtection && !features.pinCached)
533
+ return true;
534
+ if (features.passphraseProtection && !features.passphraseCached)
535
+ return true;
536
+ return false;
537
+ }
538
+ async getPublicKeys(getPublicKeys) {
539
+ const publicKeys = [];
540
+ for (let i = 0; i < getPublicKeys.length; i++) {
541
+ const { coin, addressNList, curve, showDisplay, scriptType } = getPublicKeys[i];
542
+ const GPK = new Messages.GetPublicKey();
543
+ if (coin)
544
+ GPK.setCoinName(coin);
545
+ GPK.setAddressNList(addressNList);
546
+ GPK.setShowDisplay(showDisplay || false);
547
+ GPK.setEcdsaCurveName(curve || 'secp256k1');
548
+ GPK.setScriptType((0, utils_1.translateInputScriptType)(scriptType || core.BTCInputScriptType.SpendAddress));
549
+ const event = await this.transport.call(Messages.MessageType.MESSAGETYPE_GETPUBLICKEY, GPK, {
550
+ msgTimeout: showDisplay ? core.LONG_TIMEOUT : core.DEFAULT_TIMEOUT,
551
+ });
552
+ const publicKey = event.proto;
553
+ publicKeys.push({ xpub: core.mustBeDefined(publicKey.getXpub()) });
554
+ }
555
+ return publicKeys;
556
+ }
557
+ async ping(msg) {
558
+ const ping = new Messages.Ping();
559
+ ping.setMessage(msg.msg);
560
+ ping.setButtonProtection(msg.button || false);
561
+ ping.setPinProtection(msg.pin || false);
562
+ ping.setPassphraseProtection(msg.passphrase || false);
563
+ const event = await this.transport.call(Messages.MessageType.MESSAGETYPE_PING, ping, {
564
+ msgTimeout: msg.button || msg.pin || msg.passphrase ? core.LONG_TIMEOUT : core.DEFAULT_TIMEOUT,
565
+ });
566
+ const message = event.proto;
567
+ return { msg: core.mustBeDefined(message.getMessage()) };
568
+ }
569
+ async reset(msg) {
570
+ const resetDevice = new Messages.ResetDevice();
571
+ resetDevice.setStrength(msg.entropy || 128);
572
+ resetDevice.setDisplayRandom(false);
573
+ resetDevice.setPassphraseProtection(msg.passphrase || false);
574
+ resetDevice.setPinProtection(msg.pin || false);
575
+ resetDevice.setLabel(msg.label);
576
+ if (msg.autoLockDelayMs) {
577
+ resetDevice.setAutoLockDelayMs(msg.autoLockDelayMs);
578
+ }
579
+ resetDevice.setU2fCounter(msg.u2fCounter || Math.floor(+new Date() / 1000));
580
+ // resetDevice.setWordsPerGape(wordsPerScreen) // Re-enable when patch gets in
581
+ // Send
582
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_RESETDEVICE, resetDevice, {
583
+ msgTimeout: core.LONG_TIMEOUT,
584
+ });
585
+ this.cacheFeatures(undefined);
586
+ }
587
+ async recover(r) {
588
+ const msg = new Messages.RecoveryDevice();
589
+ msg.setWordCount({ 128: 12, 192: 18, 256: 24 }[r.entropy]);
590
+ msg.setPassphraseProtection(r.passphrase);
591
+ msg.setPinProtection(r.pin);
592
+ msg.setLabel(r.label);
593
+ msg.setLanguage(r.language || 'english');
594
+ msg.setEnforceWordlist(true);
595
+ msg.setUseCharacterCipher(true);
596
+ if (r.autoLockDelayMs) {
597
+ msg.setAutoLockDelayMs(r.autoLockDelayMs);
598
+ }
599
+ msg.setU2fCounter(r.u2fCounter || Math.floor(+new Date() / 1000));
600
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_RECOVERYDEVICE, msg, {
601
+ msgTimeout: core.LONG_TIMEOUT,
602
+ });
603
+ this.cacheFeatures(undefined);
604
+ }
605
+ async pressYes() {
606
+ return this.press(true);
607
+ }
608
+ async pressNo() {
609
+ return this.press(false);
610
+ }
611
+ async press(isYes) {
612
+ const decision = new Messages.DebugLinkDecision();
613
+ decision.setYesNo(isYes);
614
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_DEBUGLINKDECISION, decision, {
615
+ noWait: true,
616
+ debugLink: true,
617
+ });
618
+ }
619
+ async sendPin(pin) {
620
+ const matrixAck = new Messages.PinMatrixAck();
621
+ matrixAck.setPin(pin);
622
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_PINMATRIXACK, matrixAck, {
623
+ msgTimeout: core.DEFAULT_TIMEOUT,
624
+ omitLock: true,
625
+ noWait: true,
626
+ });
627
+ }
628
+ async sendPassphrase(passphrase) {
629
+ const passphraseAck = new Messages.PassphraseAck();
630
+ passphraseAck.setPassphrase(passphrase);
631
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_PASSPHRASEACK, passphraseAck, {
632
+ msgTimeout: core.DEFAULT_TIMEOUT,
633
+ omitLock: true,
634
+ noWait: true,
635
+ });
636
+ }
637
+ async sendCharacter(character) {
638
+ await this.sendCharacterProto(character, false, false);
639
+ }
640
+ async sendCharacterDelete() {
641
+ await this.sendCharacterProto('', true, false);
642
+ }
643
+ async sendCharacterDone() {
644
+ await this.sendCharacterProto('', false, true);
645
+ }
646
+ async sendWord(_word) {
647
+ throw new Error('Not Yet Implemented :(');
648
+ }
649
+ async sendCharacterProto(character, _delete, _done) {
650
+ const characterAck = new Messages.CharacterAck();
651
+ if (character !== '') {
652
+ characterAck.setCharacter(character);
653
+ }
654
+ else if (_delete) {
655
+ characterAck.setDelete(_delete);
656
+ }
657
+ else if (_done) {
658
+ characterAck.setDone(_done);
659
+ }
660
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_CHARACTERACK, characterAck, {
661
+ msgTimeout: core.DEFAULT_TIMEOUT,
662
+ omitLock: true,
663
+ noWait: true,
664
+ });
665
+ }
666
+ // ApplyPolicy enables or disables a named policy such as "ShapeShift" on the device
667
+ async applyPolicy(p) {
668
+ const policy = new Types.PolicyType();
669
+ policy.setPolicyName(p.policyName);
670
+ policy.setEnabled(p.enabled);
671
+ const applyPolicies = new Messages.ApplyPolicies();
672
+ applyPolicies.setPolicyList([policy]);
673
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_APPLYPOLICIES, applyPolicies, {
674
+ msgTimeout: core.LONG_TIMEOUT,
675
+ });
676
+ this.cacheFeatures(undefined);
677
+ }
678
+ // ApplySettings changes the label, language, and enabling/disabling the passphrase
679
+ // The default language is english
680
+ async applySettings(s) {
681
+ const applySettings = new Messages.ApplySettings();
682
+ if (s.label) {
683
+ applySettings.setLabel(s.label);
684
+ }
685
+ if (s.language) {
686
+ applySettings.setLanguage(s.language);
687
+ }
688
+ if (s.usePassphrase !== undefined) {
689
+ applySettings.setUsePassphrase(s.usePassphrase);
690
+ }
691
+ if (s.autoLockDelayMs) {
692
+ applySettings.setAutoLockDelayMs(s.autoLockDelayMs);
693
+ }
694
+ if (s.u2fCounter) {
695
+ applySettings.setU2fCounter(s.u2fCounter);
696
+ }
697
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_APPLYSETTINGS, applySettings);
698
+ this.cacheFeatures(undefined);
699
+ }
700
+ // Cancel aborts the last device action that required user interaction
701
+ // It can follow a button request, passphrase request, or pin request
702
+ async cancel() {
703
+ await this.transport.cancel();
704
+ }
705
+ // ChangePin requests setting/changing the pin
706
+ async changePin() {
707
+ const changePin = new Messages.ChangePin();
708
+ // User may be propmpted for button press up to 2 times
709
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_CHANGEPIN, changePin, {
710
+ msgTimeout: core.LONG_TIMEOUT,
711
+ });
712
+ }
713
+ // CipherKeyValue encrypts or decrypts a value with a given key, nodepath, and initializationVector
714
+ // This method encrypts if encrypt is true and decrypts if false, the confirm paramater determines wether
715
+ // the user is prompted on the device. See EncryptKeyValue() and DecryptKeyValue() for convenience methods
716
+ // NOTE: If the length of the value in bytes is not divisible by 16 it will be zero padded
717
+ async cipherKeyValue(v) {
718
+ // if(val.length % 16 !== 0) val = val.concat() TODO THIS
719
+ const cipherKeyValue = new Messages.CipherKeyValue();
720
+ cipherKeyValue.setAddressNList(v.addressNList);
721
+ cipherKeyValue.setKey(v.key);
722
+ cipherKeyValue.setValue(v.value);
723
+ cipherKeyValue.setEncrypt(!!v.encrypt);
724
+ cipherKeyValue.setAskOnEncrypt(v.askOnEncrypt || false);
725
+ cipherKeyValue.setAskOnDecrypt(v.askOnDecrypt || false);
726
+ cipherKeyValue.setIv(v.iv || '');
727
+ const response = await this.transport.call(Messages.MessageType.MESSAGETYPE_CIPHERKEYVALUE, cipherKeyValue);
728
+ const ckv = response.message;
729
+ return ckv.getValue();
730
+ }
731
+ // ClearSession clears cached session values such as the pin and passphrase
732
+ async clearSession() {
733
+ const clearSession = new Messages.ClearSession();
734
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_CLEARSESSION, clearSession);
735
+ this.cacheFeatures(undefined);
736
+ }
737
+ // DecryptKeyValue is a convenience method around decrypting with CipherKeyValue().
738
+ // For more granular control of the process use CipherKeyValue()
739
+ async decryptKeyValue(v) {
740
+ return this.cipherKeyValue(v);
741
+ }
742
+ // FirmwareErase askes the device to erase its firmware
743
+ async firmwareErase() {
744
+ const firmwareErase = new Messages.FirmwareErase();
745
+ // send
746
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_FIRMWAREERASE, firmwareErase);
747
+ this.cacheFeatures(undefined);
748
+ }
749
+ async firmwareUpload(firmware) {
750
+ const firmwareUpload = new Messages.FirmwareUpload();
751
+ const hash = await this.transport.getFirmwareHash(firmware);
752
+ firmwareUpload.setPayload(firmware);
753
+ firmwareUpload.setPayloadHash(hash);
754
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_FIRMWAREUPLOAD, firmwareUpload);
755
+ this.cacheFeatures(undefined);
756
+ }
757
+ // Initialize assigns a hid connection to this KeepKey and send initialize message to device
758
+ async initialize() {
759
+ const initialize = new Messages.Initialize();
760
+ const event = await this.transport.call(Messages.MessageType.MESSAGETYPE_INITIALIZE, initialize);
761
+ if (!event.message)
762
+ throw event;
763
+ const out = event.message;
764
+ this.features = out;
765
+ // v6.1.0 firmware changed usb serial numbers to match STM32 desig_device_id
766
+ // If the deviceId in the features table doesn't match, then we need to
767
+ // add another k-v pair to the keyring so it can be looked up either way.
768
+ const transportDeviceID = await this.transport.getDeviceID();
769
+ if (out.deviceId && transportDeviceID !== out.deviceId) {
770
+ this.transport.keyring.addAlias(transportDeviceID, out.deviceId);
771
+ }
772
+ const fwVersion = `v${out.majorVersion}.${out.minorVersion}.${out.patchVersion}`;
773
+ //Lost Support per proto 44.3
774
+ this._supportsOsmosis = semver_1.default.gte(fwVersion, 'v7.7.0');
775
+ this._supportsCosmos = semver_1.default.gte(fwVersion, 'v7.3.0');
776
+ this._supportsRipple = semver_1.default.gte(fwVersion, 'v6.4.0');
777
+ this._supportsBinance = semver_1.default.gte(fwVersion, 'v6.4.0');
778
+ this._supportsEos = semver_1.default.gte(fwVersion, 'v6.4.0');
779
+ // this._supportsThorchain = semver.get(fwVersion, "v7.3.0");
780
+ this.cacheFeatures(out);
781
+ return out;
782
+ }
783
+ // GetFeatures returns the features and other device information such as the version, label, and supported coins
784
+ async getFeatures(cached = false) {
785
+ if (cached && this.featuresCache)
786
+ return this.featuresCache;
787
+ const features = new Messages.GetFeatures();
788
+ const event = await this.transport.call(Messages.MessageType.MESSAGETYPE_GETFEATURES, features);
789
+ this.cacheFeatures(event.message);
790
+ return event.message;
791
+ }
792
+ cacheFeatures(features) {
793
+ this.featuresCache = features;
794
+ }
795
+ // GetEntropy requests sample data from the hardware RNG
796
+ async getEntropy(size) {
797
+ const getEntropy = new Messages.GetEntropy();
798
+ getEntropy.setSize(size);
799
+ // send
800
+ const event = await this.transport.call(Messages.MessageType.MESSAGETYPE_GETENTROPY, getEntropy, {
801
+ msgTimeout: core.LONG_TIMEOUT,
802
+ });
803
+ return core.mustBeDefined(event.proto).getEntropy_asU8();
804
+ }
805
+ // GetNumCoins returns the number of coins supported by the device regardless of if the hanve funds.
806
+ async getNumCoins() {
807
+ const getCoinTable = new Messages.GetCoinTable();
808
+ const response = await this.transport.call(Messages.MessageType.MESSAGETYPE_GETCOINTABLE, getCoinTable);
809
+ return core.mustBeDefined(core.mustBeDefined(response.proto).getNumCoins());
810
+ }
811
+ // GetCoinTable returns an array of Types.CoinTypes, with start and end arguments for paging.
812
+ // You cannot request more than 10 at a time.
813
+ async getCoinTable(start = 0, end = start + 10) {
814
+ const getCoinTable = new Messages.GetCoinTable();
815
+ getCoinTable.setStart(start);
816
+ getCoinTable.setEnd(end);
817
+ const response = await this.transport.call(Messages.MessageType.MESSAGETYPE_GETCOINTABLE, getCoinTable);
818
+ const coinTable = response.message;
819
+ return coinTable.tableList;
820
+ }
821
+ // LoadDevice loads a provided seed onto the device and applies the provided settings
822
+ // including setting a pin/device label, enabling/disabling the passphrase, and whether to
823
+ // check the checksum of the provided mnemonic
824
+ async loadDevice(msg) {
825
+ const loadDevice = new Messages.LoadDevice();
826
+ loadDevice.setMnemonic(msg.mnemonic);
827
+ loadDevice.setPassphraseProtection(!!msg.passphrase);
828
+ loadDevice.setSkipChecksum(!!msg.skipChecksum);
829
+ if (msg.pin)
830
+ loadDevice.setPin(msg.pin);
831
+ if (msg.label)
832
+ loadDevice.setLabel(msg.label);
833
+ // send
834
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_LOADDEVICE, loadDevice, {
835
+ msgTimeout: core.LONG_TIMEOUT,
836
+ });
837
+ this.cacheFeatures(undefined);
838
+ }
839
+ // RemovePin disables pin protection for the device. If a pin is currently enabled
840
+ // it will prompt the user to enter the current pin
841
+ async removePin() {
842
+ const changePin = new Messages.ChangePin();
843
+ changePin.setRemove(true);
844
+ // send
845
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_CHANGEPIN, changePin);
846
+ this.cacheFeatures(undefined);
847
+ }
848
+ async send(events) {
849
+ for (const event of events) {
850
+ const MessageType = typeRegistry_1.messageTypeRegistry[core.mustBeDefined(event.message_enum)];
851
+ const msg = new MessageType();
852
+ Object.entries(event.message).forEach(([key, value]) => {
853
+ const setterMethod = (0, utils_1.protoFieldToSetMethod)(key);
854
+ if (msg[setterMethod]) {
855
+ // Assume setter methods are always of the format: strength -> setStrength
856
+ // until this exists https://github.com/protocolbuffers/protobuf/issues/1591
857
+ msg[setterMethod](value);
858
+ }
859
+ });
860
+ await this.transport.call(core.mustBeDefined(event.message_enum), msg);
861
+ }
862
+ }
863
+ // SoftReset power cycles the device. The device only responds to
864
+ // this message while in manufacturer mode
865
+ async softReset() {
866
+ const softReset = new Messages.SoftReset();
867
+ // send
868
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_SOFTRESET, softReset);
869
+ this.cacheFeatures(undefined);
870
+ }
871
+ // WipeDevice wipes all sensitive data and settings
872
+ async wipe() {
873
+ const wipeDevice = new Messages.WipeDevice();
874
+ // send
875
+ await this.transport.call(Messages.MessageType.MESSAGETYPE_WIPEDEVICE, wipeDevice);
876
+ this.cacheFeatures(undefined);
877
+ }
878
+ async btcGetAddress(msg) {
879
+ return Btc.btcGetAddress(this, this.transport, msg);
880
+ }
881
+ async btcSignTx(msg) {
882
+ return Btc.btcSignTx(this, this.transport, msg);
883
+ }
884
+ async btcSignMessage(msg) {
885
+ return Btc.btcSignMessage(this, this.transport, msg);
886
+ }
887
+ async btcVerifyMessage(msg) {
888
+ return Btc.btcVerifyMessage(this, this.transport, msg);
889
+ }
890
+ async ethSignTx(msg) {
891
+ return Eth.ethSignTx(this.transport, msg);
892
+ }
893
+ async ethGetAddress(msg) {
894
+ return Eth.ethGetAddress(this.transport, msg);
895
+ }
896
+ async ethSignMessage(msg) {
897
+ return Eth.ethSignMessage(this.transport, msg);
898
+ }
899
+ async ethSignTypedData(msg) {
900
+ return Eth.ethSignTypedData(this.transport, msg);
901
+ }
902
+ async ethVerifyMessage(msg) {
903
+ return Eth.ethVerifyMessage(this.transport, msg);
904
+ }
905
+ rippleGetAddress(msg) {
906
+ return Ripple.rippleGetAddress(this.transport, msg);
907
+ }
908
+ rippleSignTx(msg) {
909
+ return Ripple.rippleSignTx(this.transport, msg);
910
+ }
911
+ cosmosGetAddress(msg) {
912
+ return Cosmos.cosmosGetAddress(this.transport, msg);
913
+ }
914
+ cosmosSignTx(msg) {
915
+ return Cosmos.cosmosSignTx(this.transport, msg);
916
+ }
917
+ osmosisGetAddress(msg) {
918
+ return Osmosis.osmosisGetAddress(this.transport, msg);
919
+ }
920
+ osmosisSignTx(msg) {
921
+ return Osmosis.osmosisSignTx(this.transport, msg);
922
+ }
923
+ thorchainGetAddress(msg) {
924
+ return Thorchain.thorchainGetAddress(this.transport, msg);
925
+ }
926
+ thorchainSignTx(msg) {
927
+ return Thorchain.thorchainSignTx(this.transport, msg);
928
+ }
929
+ mayachainGetAddress(msg) {
930
+ return Mayachain.mayachainGetAddress(this.transport, msg);
931
+ }
932
+ mayachainSignTx(msg) {
933
+ return Mayachain.mayachainSignTx(this.transport, msg);
934
+ }
935
+ binanceGetAddress(msg) {
936
+ return Binance.binanceGetAddress(this.transport, msg);
937
+ }
938
+ binanceSignTx(msg) {
939
+ return Binance.binanceSignTx(this.transport, msg);
940
+ }
941
+ eosGetPublicKey(msg) {
942
+ return Eos.eosGetPublicKey(this.transport, msg);
943
+ }
944
+ eosSignTx(msg) {
945
+ return Eos.eosSignTx(this.transport, msg);
946
+ }
947
+ disconnect() {
948
+ return this.transport.disconnect();
949
+ }
950
+ }
951
+ exports.KeepKeyHDWallet = KeepKeyHDWallet;
952
+ function info() {
953
+ return new KeepKeyHDWalletInfo();
954
+ }
955
+ exports.info = info;
956
+ function create(transport) {
957
+ return new KeepKeyHDWallet(transport);
958
+ }
959
+ exports.create = create;