@shapeshiftoss/hdwallet-ledger 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/bitcoin.js +243 -177
- package/dist/bitcoin.js.map +1 -1
- package/dist/cosmos.js +82 -38
- package/dist/cosmos.js.map +1 -1
- package/dist/currencies.js +4 -1
- package/dist/currencies.js.map +1 -1
- package/dist/ethereum.d.ts.map +1 -1
- package/dist/ethereum.js +200 -143
- package/dist/ethereum.js.map +1 -1
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/ledger.js +284 -183
- package/dist/ledger.js.map +1 -1
- package/dist/thorchain/common.js +15 -10
- package/dist/thorchain/common.js.map +1 -1
- package/dist/thorchain/hw-app-thor.js +146 -125
- package/dist/thorchain/hw-app-thor.js.map +1 -1
- package/dist/thorchain/index.js +86 -39
- package/dist/thorchain/index.js.map +1 -1
- package/dist/transport.js +29 -4
- package/dist/transport.js.map +1 -1
- package/dist/utils.js +49 -13
- package/dist/utils.js.map +1 -1
- package/dist/utxoUtils.js +73 -67
- package/dist/utxoUtils.js.map +1 -1
- package/package.json +7 -7
package/dist/bitcoin.js
CHANGED
|
@@ -1,75 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.supportedCoins = void 0;
|
|
39
|
+
exports.btcSupportsCoin = btcSupportsCoin;
|
|
40
|
+
exports.btcSupportsScriptType = btcSupportsScriptType;
|
|
41
|
+
exports.btcGetAddress = btcGetAddress;
|
|
42
|
+
exports.btcGetPublicKeys = btcGetPublicKeys;
|
|
43
|
+
exports.btcSignTx = btcSignTx;
|
|
44
|
+
exports.btcSupportsSecureTransfer = btcSupportsSecureTransfer;
|
|
45
|
+
exports.btcSupportsNativeShapeShift = btcSupportsNativeShapeShift;
|
|
46
|
+
exports.btcSignMessage = btcSignMessage;
|
|
47
|
+
exports.btcVerifyMessage = btcVerifyMessage;
|
|
48
|
+
exports.btcGetAccountPaths = btcGetAccountPaths;
|
|
49
|
+
exports.btcIsSameAccount = btcIsSameAccount;
|
|
50
|
+
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
51
|
+
const base64_js_1 = __importDefault(require("base64-js"));
|
|
52
|
+
const bchAddr = __importStar(require("bchaddrjs"));
|
|
53
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
54
|
+
const bitcoinMsg = __importStar(require("bitcoinjs-message"));
|
|
55
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
56
|
+
const currencies_1 = require("./currencies");
|
|
57
|
+
const utils_1 = require("./utils");
|
|
58
|
+
const utxoUtils_1 = require("./utxoUtils");
|
|
59
|
+
exports.supportedCoins = ["Testnet", "Bitcoin", "BitcoinCash", "Litecoin", "Dash", "DigiByte", "Dogecoin"];
|
|
11
60
|
const segwitCoins = ["Bitcoin", "DigiByte", "Litecoin", "BitcoinGold", "Testnet"];
|
|
12
|
-
|
|
13
|
-
return
|
|
61
|
+
function btcSupportsCoin(coin) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return exports.supportedCoins.includes(coin);
|
|
64
|
+
});
|
|
14
65
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
66
|
+
function btcSupportsScriptType(coin, scriptType) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const supported = {
|
|
69
|
+
Bitcoin: [
|
|
70
|
+
core.BTCInputScriptType.SpendAddress,
|
|
71
|
+
core.BTCInputScriptType.SpendWitness,
|
|
72
|
+
core.BTCInputScriptType.SpendP2SHWitness,
|
|
73
|
+
],
|
|
74
|
+
BitcoinCash: [core.BTCInputScriptType.SpendAddress],
|
|
75
|
+
};
|
|
76
|
+
const scriptTypes = supported[coin];
|
|
77
|
+
return !!scriptTypes && !!scriptType && scriptTypes.includes(scriptType);
|
|
78
|
+
});
|
|
26
79
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
80
|
+
function btcGetAddress(transport, msg) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const bip32path = core.addressNListToBIP32(msg.addressNList);
|
|
83
|
+
const scriptTypeish = (() => {
|
|
84
|
+
if (msg.coin === "BitcoinCash")
|
|
85
|
+
return core.BTCInputScriptType.CashAddr;
|
|
86
|
+
if (msg.scriptType)
|
|
87
|
+
return msg.scriptType;
|
|
88
|
+
return core.BTCInputScriptType.SpendAddress;
|
|
89
|
+
})();
|
|
90
|
+
const opts = {
|
|
91
|
+
verify: !!msg.showDisplay,
|
|
92
|
+
format: (0, utils_1.translateScriptType)(scriptTypeish),
|
|
93
|
+
};
|
|
94
|
+
const res = yield transport.call("Btc", "getWalletPublicKey", bip32path, opts);
|
|
95
|
+
(0, utils_1.handleError)(res, transport, "Unable to obtain BTC address from device");
|
|
96
|
+
const address = res.payload.bitcoinAddress;
|
|
97
|
+
return msg.coin.toLowerCase() === "bitcoincash" ? bchAddr.toCashAddress(address) : address;
|
|
98
|
+
});
|
|
44
99
|
}
|
|
45
100
|
// Adapted from https://github.com/LedgerHQ/ledger-wallet-webtool
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
101
|
+
function btcGetPublicKeys(transport, msg) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const xpubs = [];
|
|
104
|
+
for (const getPublicKey of msg) {
|
|
105
|
+
const { addressNList, coin } = getPublicKey;
|
|
106
|
+
if (!coin)
|
|
107
|
+
throw new Error("coin is required");
|
|
108
|
+
if (!getPublicKey.scriptType)
|
|
109
|
+
throw new Error("scriptType is required");
|
|
110
|
+
const parentBip32path = core.addressNListToBIP32(addressNList);
|
|
111
|
+
const getWalletXpubResponse = yield transport.call("Btc", "getWalletXpub", {
|
|
112
|
+
path: parentBip32path,
|
|
113
|
+
xpubVersion: currencies_1.currencies[getPublicKey.coin].xpubVersion,
|
|
114
|
+
});
|
|
115
|
+
(0, utils_1.handleError)(getWalletXpubResponse, transport, "Unable to obtain public key from device.");
|
|
116
|
+
const { payload: _xpub } = getWalletXpubResponse;
|
|
117
|
+
// Ledger returns
|
|
118
|
+
// - LTC pubkeys in Ltub format for all scriptTypes.
|
|
119
|
+
// - BTC pubkeys in xpub format for all scriptTypes
|
|
120
|
+
// - Doge pubkeys in xpub format instead of dgub
|
|
121
|
+
// They *are* the correct accounts, but not in the format we want.
|
|
122
|
+
// We need to convert SegWit pubkeys to Mtubs/ypubs, and SegWit native to zpubs, and Doge xpubs to dgubs.
|
|
123
|
+
const xpub = (0, utxoUtils_1.convertXpubVersion)(_xpub, utxoUtils_1.scriptTypeToAccountType[getPublicKey.scriptType], getPublicKey.coin);
|
|
124
|
+
xpubs.push({
|
|
125
|
+
xpub,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return xpubs;
|
|
129
|
+
});
|
|
73
130
|
}
|
|
74
131
|
/*
|
|
75
132
|
Sign Transaction UTXO's
|
|
@@ -112,126 +169,135 @@ Parameters
|
|
|
112
169
|
* expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
113
170
|
* useTrustedInputForSegwit trust inputs for segwit transactions
|
|
114
171
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
172
|
+
function btcSignTx(wallet, transport, msg) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const supportsSecureTransfer = yield wallet.btcSupportsSecureTransfer();
|
|
175
|
+
const slip44 = core.mustBeDefined(core.slip44ByCoin(msg.coin));
|
|
176
|
+
const txBuilder = new bitcoin.TransactionBuilder(utils_1.networksUtil[slip44].bitcoinjs);
|
|
177
|
+
const indexes = [];
|
|
178
|
+
const txs = [];
|
|
179
|
+
const associatedKeysets = [];
|
|
180
|
+
let segwit = false;
|
|
181
|
+
for (const output of msg.outputs) {
|
|
182
|
+
let outputAddress;
|
|
183
|
+
if (output.addressNList !== undefined && output.isChange) {
|
|
184
|
+
const maybeOutputAddress = yield wallet.btcGetAddress({
|
|
185
|
+
addressNList: output.addressNList,
|
|
186
|
+
scriptType: output.scriptType,
|
|
187
|
+
coin: msg.coin,
|
|
188
|
+
});
|
|
189
|
+
if (!maybeOutputAddress)
|
|
190
|
+
throw new Error("could not determine output address from addressNList");
|
|
191
|
+
outputAddress = maybeOutputAddress;
|
|
192
|
+
}
|
|
193
|
+
else if (output.addressNList !== undefined &&
|
|
194
|
+
output.addressType === core.BTCOutputAddressType.Transfer &&
|
|
195
|
+
!supportsSecureTransfer) {
|
|
196
|
+
throw new Error("Ledger does not support SecureTransfer");
|
|
197
|
+
}
|
|
198
|
+
else if (output.address !== undefined) {
|
|
199
|
+
outputAddress = output.address;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
throw new Error("could not determine output address");
|
|
203
|
+
}
|
|
204
|
+
if (msg.coin === "BitcoinCash" && bchAddr.isCashAddress(outputAddress)) {
|
|
205
|
+
outputAddress = bchAddr.toLegacyAddress(outputAddress);
|
|
206
|
+
}
|
|
207
|
+
txBuilder.addOutput(outputAddress, Number(output.amount));
|
|
134
208
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
209
|
+
if (msg.opReturnData) {
|
|
210
|
+
if (msg.opReturnData.length > 80) {
|
|
211
|
+
throw new Error("OP_RETURN data must be less than 80 chars.");
|
|
212
|
+
}
|
|
213
|
+
const ret = bitcoin.script.compile([bitcoin.opcodes.OP_RETURN, Buffer.from(msg.opReturnData)]);
|
|
214
|
+
txBuilder.addOutput(ret, 0);
|
|
139
215
|
}
|
|
140
|
-
|
|
141
|
-
|
|
216
|
+
const unsignedHex = txBuilder.buildIncomplete().toHex();
|
|
217
|
+
const splitTxRes = yield transport.call("Btc", "splitTransaction", unsignedHex);
|
|
218
|
+
(0, utils_1.handleError)(splitTxRes, transport, "splitTransaction failed");
|
|
219
|
+
const outputScriptRes = yield transport.call("Btc", "serializeTransactionOutputs", splitTxRes.payload);
|
|
220
|
+
(0, utils_1.handleError)(outputScriptRes, transport, "serializeTransactionOutputs failed");
|
|
221
|
+
const outputScriptHex = outputScriptRes.payload.toString("hex");
|
|
222
|
+
for (let i = 0; i < msg.inputs.length; i++) {
|
|
223
|
+
if (msg.inputs[i].scriptType === core.BTCInputScriptType.SpendWitness ||
|
|
224
|
+
msg.inputs[i].scriptType === core.BTCInputScriptType.SpendP2SHWitness)
|
|
225
|
+
segwit = true;
|
|
226
|
+
const keySet = core.addressNListToBIP32(msg.inputs[i].addressNList).replace(/^m\//, "");
|
|
227
|
+
const vout = msg.inputs[i].vout;
|
|
228
|
+
const tx = yield transport.call("Btc", "splitTransaction", msg.inputs[i].hex, utils_1.networksUtil[slip44].isSegwitSupported, utils_1.networksUtil[slip44].areTransactionTimestamped);
|
|
229
|
+
(0, utils_1.handleError)(tx, transport, "splitTransaction failed");
|
|
230
|
+
indexes.push(vout);
|
|
231
|
+
txs.push(tx.payload);
|
|
232
|
+
associatedKeysets.push(keySet);
|
|
142
233
|
}
|
|
143
|
-
|
|
144
|
-
throw new Error("
|
|
234
|
+
if (txs.length !== indexes.length)
|
|
235
|
+
throw new Error("tx/index array length mismatch");
|
|
236
|
+
const inputs = lodash_1.default.zip(txs, indexes, [], []);
|
|
237
|
+
const txArgs = {
|
|
238
|
+
inputs,
|
|
239
|
+
associatedKeysets,
|
|
240
|
+
outputScriptHex,
|
|
241
|
+
additionals: (() => {
|
|
242
|
+
if (msg.coin === "BitcoinCash")
|
|
243
|
+
return ["abc"];
|
|
244
|
+
if (msg.inputs.some((input) => input.scriptType === core.BTCInputScriptType.SpendWitness))
|
|
245
|
+
return ["bech32"];
|
|
246
|
+
return [];
|
|
247
|
+
})(),
|
|
248
|
+
segwit,
|
|
249
|
+
useTrustedInputForSegwit: Boolean(segwit),
|
|
250
|
+
};
|
|
251
|
+
// "invalid data received" error from Ledger if not done this way:
|
|
252
|
+
if (utils_1.networksUtil[slip44].sigHash) {
|
|
253
|
+
txArgs.sigHashType = utils_1.networksUtil[slip44].sigHash;
|
|
145
254
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
throw new Error("OP_RETURN data must be less than 80 chars.");
|
|
154
|
-
}
|
|
155
|
-
const ret = bitcoin.script.compile([bitcoin.opcodes.OP_RETURN, Buffer.from(msg.opReturnData)]);
|
|
156
|
-
txBuilder.addOutput(ret, 0);
|
|
157
|
-
}
|
|
158
|
-
const unsignedHex = txBuilder.buildIncomplete().toHex();
|
|
159
|
-
const splitTxRes = await transport.call("Btc", "splitTransaction", unsignedHex);
|
|
160
|
-
handleError(splitTxRes, transport, "splitTransaction failed");
|
|
161
|
-
const outputScriptRes = await transport.call("Btc", "serializeTransactionOutputs", splitTxRes.payload);
|
|
162
|
-
handleError(outputScriptRes, transport, "serializeTransactionOutputs failed");
|
|
163
|
-
const outputScriptHex = outputScriptRes.payload.toString("hex");
|
|
164
|
-
for (let i = 0; i < msg.inputs.length; i++) {
|
|
165
|
-
if (msg.inputs[i].scriptType === core.BTCInputScriptType.SpendWitness ||
|
|
166
|
-
msg.inputs[i].scriptType === core.BTCInputScriptType.SpendP2SHWitness)
|
|
167
|
-
segwit = true;
|
|
168
|
-
const keySet = core.addressNListToBIP32(msg.inputs[i].addressNList).replace(/^m\//, "");
|
|
169
|
-
const vout = msg.inputs[i].vout;
|
|
170
|
-
const tx = await transport.call("Btc", "splitTransaction", msg.inputs[i].hex, networksUtil[slip44].isSegwitSupported, networksUtil[slip44].areTransactionTimestamped);
|
|
171
|
-
handleError(tx, transport, "splitTransaction failed");
|
|
172
|
-
indexes.push(vout);
|
|
173
|
-
txs.push(tx.payload);
|
|
174
|
-
associatedKeysets.push(keySet);
|
|
175
|
-
}
|
|
176
|
-
if (txs.length !== indexes.length)
|
|
177
|
-
throw new Error("tx/index array length mismatch");
|
|
178
|
-
const inputs = _.zip(txs, indexes, [], []);
|
|
179
|
-
const txArgs = {
|
|
180
|
-
inputs,
|
|
181
|
-
associatedKeysets,
|
|
182
|
-
outputScriptHex,
|
|
183
|
-
additionals: (() => {
|
|
184
|
-
if (msg.coin === "BitcoinCash")
|
|
185
|
-
return ["abc"];
|
|
186
|
-
if (msg.inputs.some((input) => input.scriptType === core.BTCInputScriptType.SpendWitness))
|
|
187
|
-
return ["bech32"];
|
|
188
|
-
return [];
|
|
189
|
-
})(),
|
|
190
|
-
segwit,
|
|
191
|
-
useTrustedInputForSegwit: Boolean(segwit),
|
|
192
|
-
};
|
|
193
|
-
// "invalid data received" error from Ledger if not done this way:
|
|
194
|
-
if (networksUtil[slip44].sigHash) {
|
|
195
|
-
txArgs.sigHashType = networksUtil[slip44].sigHash;
|
|
196
|
-
}
|
|
197
|
-
const signedTx = await transport.call("Btc", "createPaymentTransaction", txArgs);
|
|
198
|
-
handleError(signedTx, transport, "Could not sign transaction with device");
|
|
199
|
-
return {
|
|
200
|
-
serializedTx: signedTx.payload,
|
|
201
|
-
signatures: [],
|
|
202
|
-
};
|
|
255
|
+
const signedTx = yield transport.call("Btc", "createPaymentTransaction", txArgs);
|
|
256
|
+
(0, utils_1.handleError)(signedTx, transport, "Could not sign transaction with device");
|
|
257
|
+
return {
|
|
258
|
+
serializedTx: signedTx.payload,
|
|
259
|
+
signatures: [],
|
|
260
|
+
};
|
|
261
|
+
});
|
|
203
262
|
}
|
|
204
|
-
|
|
205
|
-
return
|
|
263
|
+
function btcSupportsSecureTransfer() {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
return false;
|
|
266
|
+
});
|
|
206
267
|
}
|
|
207
|
-
|
|
268
|
+
function btcSupportsNativeShapeShift() {
|
|
208
269
|
return false;
|
|
209
270
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
271
|
+
function btcSignMessage(wallet, transport, msg) {
|
|
272
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
var _a;
|
|
274
|
+
const bip32path = core.addressNListToBIP32(msg.addressNList);
|
|
275
|
+
const res = yield transport.call("Btc", "signMessage", bip32path, Buffer.from(msg.message).toString("hex"));
|
|
276
|
+
(0, utils_1.handleError)(res, transport, "Could not sign message with device");
|
|
277
|
+
const v = res.payload["v"] + 27 + 4;
|
|
278
|
+
const signature = Buffer.from(v.toString(16) + res.payload["r"] + res.payload["s"], "hex").toString("hex");
|
|
279
|
+
const coin = msg.coin;
|
|
280
|
+
if (!coin)
|
|
281
|
+
throw new Error("could not determine type of coin");
|
|
282
|
+
const address = yield btcGetAddress(transport, {
|
|
283
|
+
addressNList: msg.addressNList,
|
|
284
|
+
coin,
|
|
285
|
+
showDisplay: false,
|
|
286
|
+
scriptType: (_a = msg.scriptType) !== null && _a !== void 0 ? _a : core.BTCInputScriptType.SpendAddress,
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
address,
|
|
290
|
+
signature,
|
|
291
|
+
};
|
|
224
292
|
});
|
|
225
|
-
return {
|
|
226
|
-
address,
|
|
227
|
-
signature,
|
|
228
|
-
};
|
|
229
293
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
294
|
+
function btcVerifyMessage(msg) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
const signature = base64_js_1.default.fromByteArray(core.fromHexString(msg.signature));
|
|
297
|
+
return bitcoinMsg.verify(msg.message, msg.address, signature);
|
|
298
|
+
});
|
|
233
299
|
}
|
|
234
|
-
|
|
300
|
+
function btcGetAccountPaths(msg) {
|
|
235
301
|
const slip44 = core.slip44ByCoin(msg.coin);
|
|
236
302
|
if (slip44 === undefined)
|
|
237
303
|
return [];
|
|
@@ -262,7 +328,7 @@ export function btcGetAccountPaths(msg) {
|
|
|
262
328
|
return paths;
|
|
263
329
|
}
|
|
264
330
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
265
|
-
|
|
331
|
+
function btcIsSameAccount(msg) {
|
|
266
332
|
// TODO: There's no way this is correct.
|
|
267
333
|
return true;
|
|
268
334
|
}
|
package/dist/bitcoin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin.js","sourceRoot":"","sources":["../src/bitcoin.ts"],"names":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