@shapeshiftoss/hdwallet-keepkey 1.55.4-alpha.1 → 1.55.4
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/adapter.js +148 -93
- package/dist/adapter.js.map +1 -1
- package/dist/binance.js +135 -96
- package/dist/binance.js.map +1 -1
- package/dist/bitcoin.js +323 -257
- package/dist/bitcoin.js.map +1 -1
- package/dist/bnbencoding.js +40 -9
- package/dist/bnbencoding.js.map +1 -1
- package/dist/cosmos.js +206 -158
- package/dist/cosmos.js.map +1 -1
- package/dist/eos.js +152 -108
- package/dist/eos.js.map +1 -1
- package/dist/ethereum.js +242 -189
- package/dist/ethereum.js.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/keepkey.js +582 -444
- package/dist/keepkey.js.map +1 -1
- package/dist/osmosis.js +259 -211
- package/dist/osmosis.js.map +1 -1
- package/dist/ripple.js +96 -52
- package/dist/ripple.js.map +1 -1
- package/dist/thorchain.js +162 -114
- package/dist/thorchain.js.map +1 -1
- package/dist/transport.js +278 -220
- package/dist/transport.js.map +1 -1
- package/dist/typeRegistry.js +41 -12
- package/dist/typeRegistry.js.map +1 -1
- package/dist/utils.js +37 -7
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/dist/bitcoin.js
CHANGED
|
@@ -1,10 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.btcSupportsCoin = btcSupportsCoin;
|
|
39
|
+
exports.btcSupportsScriptType = btcSupportsScriptType;
|
|
40
|
+
exports.btcGetAddress = btcGetAddress;
|
|
41
|
+
exports.btcSignTx = btcSignTx;
|
|
42
|
+
exports.btcSupportsSecureTransfer = btcSupportsSecureTransfer;
|
|
43
|
+
exports.btcSupportsNativeShapeShift = btcSupportsNativeShapeShift;
|
|
44
|
+
exports.btcSignMessage = btcSignMessage;
|
|
45
|
+
exports.btcVerifyMessage = btcVerifyMessage;
|
|
46
|
+
exports.btcGetAccountPaths = btcGetAccountPaths;
|
|
47
|
+
exports.btcIsSameAccount = btcIsSameAccount;
|
|
48
|
+
const Messages = __importStar(require("@keepkey/device-protocol/lib/messages_pb"));
|
|
49
|
+
const Types = __importStar(require("@keepkey/device-protocol/lib/types_pb"));
|
|
50
|
+
const bitcoinjs = __importStar(require("@shapeshiftoss/bitcoinjs-lib"));
|
|
51
|
+
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
52
|
+
const assert_1 = __importDefault(require("assert"));
|
|
53
|
+
const icepick_1 = require("icepick");
|
|
54
|
+
const utils_1 = require("./utils");
|
|
8
55
|
// FIXME: load this from the device's coin table, or from some static features
|
|
9
56
|
// table... instead of, you know, adding another God-forsaken coin table.
|
|
10
57
|
// :facepalm:
|
|
@@ -51,7 +98,7 @@ function prepareSignTx(coin, inputs, outputs) {
|
|
|
51
98
|
utxo.setPrevIndex(input.vout);
|
|
52
99
|
if (input.sequence !== undefined)
|
|
53
100
|
utxo.setSequence(input.sequence);
|
|
54
|
-
utxo.setScriptType(translateInputScriptType(input.scriptType));
|
|
101
|
+
utxo.setScriptType((0, utils_1.translateInputScriptType)(input.scriptType));
|
|
55
102
|
utxo.setAddressNList(input.addressNList);
|
|
56
103
|
utxo.setAmount(Number(input.amount));
|
|
57
104
|
unsignedTx.addInputs(utxo, i);
|
|
@@ -68,7 +115,7 @@ function prepareSignTx(coin, inputs, outputs) {
|
|
|
68
115
|
}
|
|
69
116
|
if (output.isChange || output.addressType === core.BTCOutputAddressType.Transfer) {
|
|
70
117
|
// BTCSignTxOutputTranfer || BTCSignTxOutputChange
|
|
71
|
-
newOutput.setScriptType(translateOutputScriptType(output.scriptType));
|
|
118
|
+
newOutput.setScriptType((0, utils_1.translateOutputScriptType)(output.scriptType));
|
|
72
119
|
newOutput.setAddressNList(output.addressNList);
|
|
73
120
|
newOutput.setAddressType(output.isChange ? Types.OutputAddressType.CHANGE : Types.OutputAddressType.TRANSFER);
|
|
74
121
|
}
|
|
@@ -81,7 +128,7 @@ function prepareSignTx(coin, inputs, outputs) {
|
|
|
81
128
|
else {
|
|
82
129
|
// BTCSignTxOutputSpend
|
|
83
130
|
newOutput.setScriptType(Types.OutputScriptType.PAYTOADDRESS);
|
|
84
|
-
|
|
131
|
+
(0, assert_1.default)(output.address !== undefined, "Output must have a valid BTC address.");
|
|
85
132
|
newOutput.setAddress(output.address);
|
|
86
133
|
newOutput.setAddressType(Types.OutputAddressType.SPEND);
|
|
87
134
|
}
|
|
@@ -168,11 +215,13 @@ function prepareSignTx(coin, inputs, outputs) {
|
|
|
168
215
|
});
|
|
169
216
|
return txmap;
|
|
170
217
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
218
|
+
function ensureCoinSupport(wallet, coin) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
if (!supportedCoins.includes(coin))
|
|
221
|
+
throw new Error(`'${coin}' not yet supported in HDWalletKeepKey`);
|
|
222
|
+
if (!wallet.btcSupportsCoin(coin))
|
|
223
|
+
throw new Error(`'${coin} is not supported in this firmware version`);
|
|
224
|
+
});
|
|
176
225
|
}
|
|
177
226
|
function validateVoutOrdering(msg) {
|
|
178
227
|
// From THORChain specification:
|
|
@@ -191,6 +240,7 @@ function validateVoutOrdering(msg) {
|
|
|
191
240
|
- count vouts > 4
|
|
192
241
|
- count vouts with coins (value) > 2
|
|
193
242
|
*/
|
|
243
|
+
var _a;
|
|
194
244
|
// Check that vout:0 contains the vault address
|
|
195
245
|
if (msg.outputs[0].address != msg.vaultAddress) {
|
|
196
246
|
return false;
|
|
@@ -200,277 +250,293 @@ function validateVoutOrdering(msg) {
|
|
|
200
250
|
return false;
|
|
201
251
|
}
|
|
202
252
|
// Check and make sure vout:2 has OP_RETURN data
|
|
203
|
-
if (!(msg.outputs[2] && msg.outputs[2]
|
|
253
|
+
if (!(msg.outputs[2] && ((_a = msg.outputs[2]) === null || _a === void 0 ? void 0 : _a.opReturnData))) {
|
|
204
254
|
return false;
|
|
205
255
|
}
|
|
206
256
|
return true;
|
|
207
257
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (!supportedCoins.includes(coin))
|
|
214
|
-
return false;
|
|
215
|
-
if (!segwitCoins.includes(coin) && scriptType === core.BTCInputScriptType.SpendP2SHWitness)
|
|
216
|
-
return false;
|
|
217
|
-
if (!segwitCoins.includes(coin) && scriptType === core.BTCInputScriptType.SpendWitness)
|
|
218
|
-
return false;
|
|
219
|
-
return true;
|
|
258
|
+
function btcSupportsCoin(coin) {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
+
// FIXME: inspect the CoinTable to determine which coins are actually supported by the device.
|
|
261
|
+
return supportedCoins.includes(coin);
|
|
262
|
+
});
|
|
220
263
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
264
|
+
function btcSupportsScriptType(coin, scriptType) {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
if (!supportedCoins.includes(coin))
|
|
267
|
+
return false;
|
|
268
|
+
if (!segwitCoins.includes(coin) && scriptType === core.BTCInputScriptType.SpendP2SHWitness)
|
|
269
|
+
return false;
|
|
270
|
+
if (!segwitCoins.includes(coin) && scriptType === core.BTCInputScriptType.SpendWitness)
|
|
271
|
+
return false;
|
|
272
|
+
return true;
|
|
230
273
|
});
|
|
231
|
-
if (response.message_type === core.Events.CANCEL)
|
|
232
|
-
throw response;
|
|
233
|
-
const btcAddress = response.proto;
|
|
234
|
-
return core.mustBeDefined(btcAddress.getAddress());
|
|
235
274
|
}
|
|
236
|
-
|
|
237
|
-
return
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
throw new Error("OP_RETURN output character count is too damn high.");
|
|
246
|
-
}
|
|
247
|
-
msg.outputs.push({
|
|
248
|
-
addressType: core.BTCOutputAddressType.Spend,
|
|
249
|
-
opReturnData: Buffer.from(msg.opReturnData).toString("base64"),
|
|
250
|
-
amount: "0",
|
|
251
|
-
isChange: false,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
// If this is a THORChain transaction, validate the vout ordering
|
|
255
|
-
if (msg.vaultAddress && !validateVoutOrdering(msg)) {
|
|
256
|
-
throw new Error("Improper vout ordering for BTC Thorchain transaction");
|
|
257
|
-
}
|
|
258
|
-
const txmap = prepareSignTx(msg.coin, msg.inputs, msg.outputs);
|
|
259
|
-
// Prepare and send initial message
|
|
260
|
-
const tx = new Messages.SignTx();
|
|
261
|
-
tx.setInputsCount(msg.inputs.length);
|
|
262
|
-
tx.setOutputsCount(msg.outputs.length);
|
|
263
|
-
tx.setCoinName(msg.coin);
|
|
264
|
-
if (msg.version !== undefined)
|
|
265
|
-
tx.setVersion(msg.version);
|
|
266
|
-
tx.setLockTime(msg.locktime || 0);
|
|
267
|
-
let responseType;
|
|
268
|
-
let response;
|
|
269
|
-
const { message_enum, proto } = await transport.call(Messages.MessageType.MESSAGETYPE_SIGNTX, tx, {
|
|
275
|
+
function btcGetAddress(wallet, transport, msg) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
yield ensureCoinSupport(wallet, msg.coin);
|
|
278
|
+
const addr = new Messages.GetAddress();
|
|
279
|
+
addr.setAddressNList(msg.addressNList);
|
|
280
|
+
addr.setCoinName(msg.coin);
|
|
281
|
+
addr.setShowDisplay(msg.showDisplay || false);
|
|
282
|
+
addr.setScriptType((0, utils_1.translateInputScriptType)(msg.scriptType || core.BTCInputScriptType.SpendAddress));
|
|
283
|
+
const response = yield transport.call(Messages.MessageType.MESSAGETYPE_GETADDRESS, addr, {
|
|
270
284
|
msgTimeout: core.LONG_TIMEOUT,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
290
|
-
serializedTx += core.toHexString(txRequest.getSerialized().getSerializedTx_asU8());
|
|
285
|
+
});
|
|
286
|
+
if (response.message_type === core.Events.CANCEL)
|
|
287
|
+
throw response;
|
|
288
|
+
const btcAddress = response.proto;
|
|
289
|
+
return core.mustBeDefined(btcAddress.getAddress());
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function btcSignTx(wallet, transport, msgIn) {
|
|
293
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
+
return transport.lockDuring(() => __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
// Make a copy of the input parameter so as to not mutate the caller's data.
|
|
296
|
+
// Unfreezing a recursively-frozen object is nontrivial, so we leverage an existing package
|
|
297
|
+
const msg = (0, icepick_1.thaw)(msgIn);
|
|
298
|
+
msg.outputs = (0, icepick_1.thaw)(msgIn.outputs);
|
|
299
|
+
yield ensureCoinSupport(wallet, msg.coin);
|
|
300
|
+
if (msg.opReturnData) {
|
|
301
|
+
if (msg.opReturnData.length > 80) {
|
|
302
|
+
throw new Error("OP_RETURN output character count is too damn high.");
|
|
291
303
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
304
|
+
msg.outputs.push({
|
|
305
|
+
addressType: core.BTCOutputAddressType.Spend,
|
|
306
|
+
opReturnData: Buffer.from(msg.opReturnData).toString("base64"),
|
|
307
|
+
amount: "0",
|
|
308
|
+
isChange: false,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
// If this is a THORChain transaction, validate the vout ordering
|
|
312
|
+
if (msg.vaultAddress && !validateVoutOrdering(msg)) {
|
|
313
|
+
throw new Error("Improper vout ordering for BTC Thorchain transaction");
|
|
314
|
+
}
|
|
315
|
+
const txmap = prepareSignTx(msg.coin, msg.inputs, msg.outputs);
|
|
316
|
+
// Prepare and send initial message
|
|
317
|
+
const tx = new Messages.SignTx();
|
|
318
|
+
tx.setInputsCount(msg.inputs.length);
|
|
319
|
+
tx.setOutputsCount(msg.outputs.length);
|
|
320
|
+
tx.setCoinName(msg.coin);
|
|
321
|
+
if (msg.version !== undefined)
|
|
322
|
+
tx.setVersion(msg.version);
|
|
323
|
+
tx.setLockTime(msg.locktime || 0);
|
|
324
|
+
let responseType;
|
|
325
|
+
let response;
|
|
326
|
+
const { message_enum, proto } = yield transport.call(Messages.MessageType.MESSAGETYPE_SIGNTX, tx, {
|
|
327
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
328
|
+
omitLock: true,
|
|
329
|
+
}); // 5 Minute timeout
|
|
330
|
+
responseType = message_enum;
|
|
331
|
+
response = proto;
|
|
332
|
+
// Prepare structure for signatures
|
|
333
|
+
const signatures = new Array(msg.inputs.length).fill(null);
|
|
334
|
+
let serializedTx = "";
|
|
335
|
+
try {
|
|
336
|
+
// Begin callback loop
|
|
337
|
+
// eslint-disable-next-line no-constant-condition
|
|
338
|
+
while (true) {
|
|
339
|
+
if (responseType !== Messages.MessageType.MESSAGETYPE_TXREQUEST) {
|
|
340
|
+
throw new Error(`Unexpected message type: ${responseType}`);
|
|
298
341
|
}
|
|
342
|
+
const txRequest = response;
|
|
343
|
+
// If there's some part of signed transaction, add it
|
|
299
344
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
let currentTx;
|
|
307
|
-
let currentMsg;
|
|
308
|
-
let txAck;
|
|
309
|
-
// Device asked for one more information, let's process it.
|
|
310
|
-
if (!txRequest.hasDetails())
|
|
311
|
-
throw new Error("expected details");
|
|
312
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
313
|
-
const reqDetails = txRequest.getDetails();
|
|
314
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
315
|
-
if (!reqDetails.hasTxHash()) {
|
|
316
|
-
currentTx = txmap["unsigned"];
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
currentTx = txmap[core.toHexString(reqDetails.getTxHash_asU8())];
|
|
320
|
-
}
|
|
321
|
-
if (txRequest.getRequestType() === Types.RequestType.TXMETA) {
|
|
322
|
-
currentMsg = new Types.TransactionType();
|
|
345
|
+
if (txRequest.hasSerialized() && txRequest.getSerialized().hasSerializedTx()) {
|
|
346
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
347
|
+
serializedTx += core.toHexString(txRequest.getSerialized().getSerializedTx_asU8());
|
|
348
|
+
}
|
|
323
349
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
324
|
-
if (
|
|
325
|
-
|
|
350
|
+
if (txRequest.hasSerialized() && txRequest.getSerialized().hasSignatureIndex()) {
|
|
351
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
352
|
+
const sigIdx = txRequest.getSerialized().getSignatureIndex();
|
|
353
|
+
if (signatures[sigIdx] !== null) {
|
|
354
|
+
throw new Error(`Signature for index ${sigIdx} already filled`);
|
|
355
|
+
}
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
357
|
+
signatures[sigIdx] = core.toHexString(txRequest.getSerialized().getSignature_asU8());
|
|
358
|
+
}
|
|
359
|
+
if (txRequest.getRequestType() === Types.RequestType.TXFINISHED) {
|
|
360
|
+
// Device didn't ask for more information, finish workflow
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
let currentTx;
|
|
364
|
+
let currentMsg;
|
|
365
|
+
let txAck;
|
|
366
|
+
// Device asked for one more information, let's process it.
|
|
367
|
+
if (!txRequest.hasDetails())
|
|
368
|
+
throw new Error("expected details");
|
|
326
369
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
327
|
-
|
|
328
|
-
currentMsg.setLockTime(currentTx.getLockTime());
|
|
370
|
+
const reqDetails = txRequest.getDetails();
|
|
329
371
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
if (reqDetails.hasTxHash()) {
|
|
333
|
-
currentMsg.setOutputsCnt(currentTx.getBinOutputsList().length);
|
|
372
|
+
if (!reqDetails.hasTxHash()) {
|
|
373
|
+
currentTx = txmap["unsigned"];
|
|
334
374
|
}
|
|
335
375
|
else {
|
|
336
|
-
|
|
376
|
+
currentTx = txmap[core.toHexString(reqDetails.getTxHash_asU8())];
|
|
337
377
|
}
|
|
338
|
-
if (
|
|
339
|
-
currentMsg.
|
|
378
|
+
if (txRequest.getRequestType() === Types.RequestType.TXMETA) {
|
|
379
|
+
currentMsg = new Types.TransactionType();
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
381
|
+
if (currentTx.hasVersion())
|
|
382
|
+
currentMsg.setVersion(currentTx.getVersion());
|
|
383
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
384
|
+
if (currentTx.hasLockTime())
|
|
385
|
+
currentMsg.setLockTime(currentTx.getLockTime());
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
387
|
+
if (currentTx.hasInputsCnt())
|
|
388
|
+
currentMsg.setInputsCnt(currentTx.getInputsCnt());
|
|
389
|
+
if (reqDetails.hasTxHash()) {
|
|
390
|
+
currentMsg.setOutputsCnt(currentTx.getBinOutputsList().length);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
currentMsg.setOutputsCnt(currentTx.getOutputsList().length);
|
|
394
|
+
}
|
|
395
|
+
if (currentTx.hasExtraData()) {
|
|
396
|
+
currentMsg.setExtraDataLen(currentTx.getExtraData_asU8().length);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
currentMsg.setExtraDataLen(0);
|
|
400
|
+
}
|
|
401
|
+
txAck = new Messages.TxAck();
|
|
402
|
+
txAck.setTx(currentMsg);
|
|
403
|
+
const message = yield transport.call(Messages.MessageType.MESSAGETYPE_TXACK, txAck, {
|
|
404
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
405
|
+
omitLock: true,
|
|
406
|
+
}); // 5 Minute timeout
|
|
407
|
+
responseType = message.message_enum;
|
|
408
|
+
response = message.proto;
|
|
409
|
+
continue;
|
|
340
410
|
}
|
|
341
|
-
|
|
342
|
-
|
|
411
|
+
if (txRequest.getRequestType() === Types.RequestType.TXINPUT) {
|
|
412
|
+
if (!reqDetails.hasRequestIndex())
|
|
413
|
+
throw new Error("expected request index");
|
|
414
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
415
|
+
const reqIndex = reqDetails.getRequestIndex();
|
|
416
|
+
currentMsg = new Types.TransactionType();
|
|
417
|
+
currentMsg.setInputsList([currentTx.getInputsList()[reqIndex]]);
|
|
418
|
+
txAck = new Messages.TxAck();
|
|
419
|
+
txAck.setTx(currentMsg);
|
|
420
|
+
const message = yield transport.call(Messages.MessageType.MESSAGETYPE_TXACK, txAck, {
|
|
421
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
422
|
+
omitLock: true,
|
|
423
|
+
}); // 5 Minute timeout
|
|
424
|
+
responseType = message.message_enum;
|
|
425
|
+
response = message.proto;
|
|
426
|
+
continue;
|
|
343
427
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}); // 5 Minute timeout
|
|
367
|
-
responseType = message.message_enum;
|
|
368
|
-
response = message.proto;
|
|
369
|
-
continue;
|
|
370
|
-
}
|
|
371
|
-
if (txRequest.getRequestType() === Types.RequestType.TXOUTPUT) {
|
|
372
|
-
if (!reqDetails.hasRequestIndex())
|
|
373
|
-
throw new Error("expected request index");
|
|
374
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
375
|
-
const reqIndex = reqDetails.getRequestIndex();
|
|
376
|
-
currentMsg = new Types.TransactionType();
|
|
377
|
-
if (reqDetails.hasTxHash()) {
|
|
378
|
-
currentMsg.setBinOutputsList([currentTx.getBinOutputsList()[reqIndex]]);
|
|
428
|
+
if (txRequest.getRequestType() === Types.RequestType.TXOUTPUT) {
|
|
429
|
+
if (!reqDetails.hasRequestIndex())
|
|
430
|
+
throw new Error("expected request index");
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
432
|
+
const reqIndex = reqDetails.getRequestIndex();
|
|
433
|
+
currentMsg = new Types.TransactionType();
|
|
434
|
+
if (reqDetails.hasTxHash()) {
|
|
435
|
+
currentMsg.setBinOutputsList([currentTx.getBinOutputsList()[reqIndex]]);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
currentMsg.setOutputsList([currentTx.getOutputsList()[reqIndex]]);
|
|
439
|
+
currentMsg.setOutputsCnt(1);
|
|
440
|
+
}
|
|
441
|
+
txAck = new Messages.TxAck();
|
|
442
|
+
txAck.setTx(currentMsg);
|
|
443
|
+
const message = yield transport.call(Messages.MessageType.MESSAGETYPE_TXACK, txAck, {
|
|
444
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
445
|
+
omitLock: true,
|
|
446
|
+
}); // 5 Minute timeout
|
|
447
|
+
responseType = message.message_enum;
|
|
448
|
+
response = message.proto;
|
|
449
|
+
continue;
|
|
379
450
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
451
|
+
if (txRequest.getRequestType() === Types.RequestType.TXEXTRADATA) {
|
|
452
|
+
if (!reqDetails.hasExtraDataOffset() || !reqDetails.hasExtraDataLen())
|
|
453
|
+
throw new Error("missing extra data offset and length");
|
|
454
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
455
|
+
const offset = reqDetails.getExtraDataOffset();
|
|
456
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
457
|
+
const length = reqDetails.getExtraDataLen();
|
|
458
|
+
currentMsg = new Types.TransactionType();
|
|
459
|
+
currentMsg.setExtraData(currentTx.getExtraData_asU8().slice(offset, offset + length));
|
|
460
|
+
txAck = new Messages.TxAck();
|
|
461
|
+
txAck.setTx(currentMsg);
|
|
462
|
+
const message = yield transport.call(Messages.MessageType.MESSAGETYPE_TXACK, txAck, {
|
|
463
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
464
|
+
omitLock: true,
|
|
465
|
+
}); // 5 Minute timeout
|
|
466
|
+
responseType = message.message_enum;
|
|
467
|
+
response = message.proto;
|
|
468
|
+
continue;
|
|
383
469
|
}
|
|
384
|
-
txAck = new Messages.TxAck();
|
|
385
|
-
txAck.setTx(currentMsg);
|
|
386
|
-
const message = await transport.call(Messages.MessageType.MESSAGETYPE_TXACK, txAck, {
|
|
387
|
-
msgTimeout: core.LONG_TIMEOUT,
|
|
388
|
-
omitLock: true,
|
|
389
|
-
}); // 5 Minute timeout
|
|
390
|
-
responseType = message.message_enum;
|
|
391
|
-
response = message.proto;
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
if (txRequest.getRequestType() === Types.RequestType.TXEXTRADATA) {
|
|
395
|
-
if (!reqDetails.hasExtraDataOffset() || !reqDetails.hasExtraDataLen())
|
|
396
|
-
throw new Error("missing extra data offset and length");
|
|
397
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
398
|
-
const offset = reqDetails.getExtraDataOffset();
|
|
399
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
400
|
-
const length = reqDetails.getExtraDataLen();
|
|
401
|
-
currentMsg = new Types.TransactionType();
|
|
402
|
-
currentMsg.setExtraData(currentTx.getExtraData_asU8().slice(offset, offset + length));
|
|
403
|
-
txAck = new Messages.TxAck();
|
|
404
|
-
txAck.setTx(currentMsg);
|
|
405
|
-
const message = await transport.call(Messages.MessageType.MESSAGETYPE_TXACK, txAck, {
|
|
406
|
-
msgTimeout: core.LONG_TIMEOUT,
|
|
407
|
-
omitLock: true,
|
|
408
|
-
}); // 5 Minute timeout
|
|
409
|
-
responseType = message.message_enum;
|
|
410
|
-
response = message.proto;
|
|
411
|
-
continue;
|
|
412
470
|
}
|
|
413
471
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
};
|
|
472
|
+
catch (error) {
|
|
473
|
+
console.error({ error });
|
|
474
|
+
throw new Error("Failed to sign BTC transaction");
|
|
475
|
+
}
|
|
476
|
+
if (signatures.includes(null)) {
|
|
477
|
+
throw new Error("Some signatures are missing!");
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
signatures: signatures,
|
|
481
|
+
serializedTx: serializedTx,
|
|
482
|
+
};
|
|
483
|
+
}));
|
|
426
484
|
});
|
|
427
485
|
}
|
|
428
|
-
|
|
429
|
-
return
|
|
486
|
+
function btcSupportsSecureTransfer() {
|
|
487
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
488
|
+
return true;
|
|
489
|
+
});
|
|
430
490
|
}
|
|
431
|
-
|
|
491
|
+
function btcSupportsNativeShapeShift() {
|
|
432
492
|
return true;
|
|
433
493
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
494
|
+
function btcSignMessage(wallet, transport, msg) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
var _a;
|
|
497
|
+
yield ensureCoinSupport(wallet, msg.coin);
|
|
498
|
+
const sign = new Messages.SignMessage();
|
|
499
|
+
sign.setAddressNList(msg.addressNList);
|
|
500
|
+
sign.setMessage((0, utils_1.toUTF8Array)(msg.message));
|
|
501
|
+
sign.setCoinName(msg.coin || "Bitcoin");
|
|
502
|
+
sign.setScriptType((0, utils_1.translateInputScriptType)((_a = msg.scriptType) !== null && _a !== void 0 ? _a : core.BTCInputScriptType.SpendAddress));
|
|
503
|
+
const event = yield transport.call(Messages.MessageType.MESSAGETYPE_SIGNMESSAGE, sign, {
|
|
504
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
505
|
+
});
|
|
506
|
+
const messageSignature = event.proto;
|
|
507
|
+
const address = messageSignature.getAddress();
|
|
508
|
+
if (!address)
|
|
509
|
+
throw new Error("btcSignMessage failed");
|
|
510
|
+
return {
|
|
511
|
+
address,
|
|
512
|
+
signature: core.toHexString(messageSignature.getSignature_asU8()),
|
|
513
|
+
};
|
|
443
514
|
});
|
|
444
|
-
const messageSignature = event.proto;
|
|
445
|
-
const address = messageSignature.getAddress();
|
|
446
|
-
if (!address)
|
|
447
|
-
throw new Error("btcSignMessage failed");
|
|
448
|
-
return {
|
|
449
|
-
address,
|
|
450
|
-
signature: core.toHexString(messageSignature.getSignature_asU8()),
|
|
451
|
-
};
|
|
452
515
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
catch (e) {
|
|
465
|
-
if (core.isIndexable(e) && e.message_enum === Messages.MessageType.MESSAGETYPE_FAILURE) {
|
|
466
|
-
return false;
|
|
516
|
+
function btcVerifyMessage(wallet, transport, msg) {
|
|
517
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
518
|
+
yield ensureCoinSupport(wallet, msg.coin);
|
|
519
|
+
const verify = new Messages.VerifyMessage();
|
|
520
|
+
verify.setAddress(msg.address);
|
|
521
|
+
verify.setSignature(core.arrayify("0x" + msg.signature));
|
|
522
|
+
verify.setMessage((0, utils_1.toUTF8Array)(msg.message));
|
|
523
|
+
verify.setCoinName(msg.coin);
|
|
524
|
+
let event;
|
|
525
|
+
try {
|
|
526
|
+
event = yield transport.call(Messages.MessageType.MESSAGETYPE_VERIFYMESSAGE, verify);
|
|
467
527
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
528
|
+
catch (e) {
|
|
529
|
+
if (core.isIndexable(e) && e.message_enum === Messages.MessageType.MESSAGETYPE_FAILURE) {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
throw e;
|
|
533
|
+
}
|
|
534
|
+
const success = event.proto;
|
|
535
|
+
return success.getMessage() === "Message verified";
|
|
536
|
+
});
|
|
472
537
|
}
|
|
473
|
-
|
|
538
|
+
function btcGetAccountPaths(msg) {
|
|
539
|
+
var _a;
|
|
474
540
|
const slip44 = core.slip44ByCoin(msg.coin);
|
|
475
541
|
if (slip44 === undefined)
|
|
476
542
|
return [];
|
|
@@ -483,7 +549,7 @@ export function btcGetAccountPaths(msg) {
|
|
|
483
549
|
const btcSegwitNative = segwitNativeAccount(msg.coin, core.slip44ByCoin("Bitcoin"), msg.accountIdx);
|
|
484
550
|
// For BCH Forks
|
|
485
551
|
const bchLegacy = legacyAccount(msg.coin, core.slip44ByCoin("BitcoinCash"), msg.accountIdx);
|
|
486
|
-
let paths = {
|
|
552
|
+
let paths = (_a = {
|
|
487
553
|
Bitcoin: [bip44, bip49, bip84],
|
|
488
554
|
Litecoin: [bip44, bip49, bip84],
|
|
489
555
|
Dash: [bip44],
|
|
@@ -493,14 +559,14 @@ export function btcGetAccountPaths(msg) {
|
|
|
493
559
|
BitcoinCash: [bip44, btcLegacy],
|
|
494
560
|
BitcoinSV: [bip44, bchLegacy, btcLegacy],
|
|
495
561
|
BitcoinGold: [bip44, bip49, bip84, btcLegacy, btcSegwit, btcSegwitNative],
|
|
496
|
-
}[msg.coin]
|
|
562
|
+
}[msg.coin]) !== null && _a !== void 0 ? _a : [];
|
|
497
563
|
if (msg.scriptType !== undefined)
|
|
498
564
|
paths = paths.filter((path) => {
|
|
499
565
|
return path.scriptType === msg.scriptType;
|
|
500
566
|
});
|
|
501
567
|
return paths;
|
|
502
568
|
}
|
|
503
|
-
|
|
569
|
+
function btcIsSameAccount(msg) {
|
|
504
570
|
if (msg.length < 1)
|
|
505
571
|
return false;
|
|
506
572
|
if (msg.length > 3)
|