Skip to content

Commit aa44234

Browse files
chore(app): use standard import name for utxolib
Issue: BG-34381
1 parent b8ebc75 commit aa44234

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

app/sign.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Promise = require('bluebird');
22
const co = Promise.coroutine;
3-
const utxoLib = require('@bitgo/utxo-lib');
3+
const utxolib = require('@bitgo/utxo-lib');
44
const accountLib = require('@bitgo/account-lib');
55
const statics = require('@bitgo/statics');
66
const fs = require('fs');
@@ -14,18 +14,18 @@ const bitgojs = require('bitgo');
1414
let bitgo;
1515

1616
const utxoNetworks = {
17-
btc: utxoLib.networks.bitcoin,
18-
ltc: utxoLib.networks.litecoin,
19-
bch: utxoLib.networks.bitcoincash,
20-
bsv: utxoLib.networks.bitcoinsv,
21-
zec: utxoLib.networks.zcash,
22-
dash: utxoLib.networks.dash,
23-
tltc: utxoLib.networks.litecoin,
24-
tbtc: utxoLib.networks.testnet,
25-
tbch: utxoLib.networks.bitcoincashTestnet,
26-
tbsv: utxoLib.networks.bitcoinsvTestnet,
27-
tzec: utxoLib.networks.zcashTest,
28-
tdash: utxoLib.networks.dashTest
17+
btc: utxolib.networks.bitcoin,
18+
ltc: utxolib.networks.litecoin,
19+
bch: utxolib.networks.bitcoincash,
20+
bsv: utxolib.networks.bitcoinsv,
21+
zec: utxolib.networks.zcash,
22+
dash: utxolib.networks.dash,
23+
tltc: utxolib.networks.litecoin,
24+
tbtc: utxolib.networks.testnet,
25+
tbch: utxolib.networks.bitcoincashTestnet,
26+
tbsv: utxolib.networks.bitcoinsvTestnet,
27+
tzec: utxolib.networks.zcashTest,
28+
tdash: utxolib.networks.dashTest
2929
};
3030

3131
const coinDecimals = {
@@ -90,7 +90,7 @@ const getHDNodeAndVerify = function(xprv, expectedXpub) {
9090
let node;
9191

9292
try {
93-
node = utxoLib.HDNode.fromBase58(xprv);
93+
node = utxolib.HDNode.fromBase58(xprv);
9494
} catch (e) {
9595
throw new Error('invalid private key');
9696
}
@@ -148,10 +148,10 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
148148
}
149149

150150
const txHex = getTransactionHexFromRequest(recoveryRequest);
151-
const transaction = utxoLib.Transaction.fromHex(txHex, network);
151+
const transaction = utxolib.Transaction.fromHex(txHex, network);
152152

153153
const outputs = transaction.outs.map(out => ({
154-
address: utxoLib.address.fromOutputScript(out.script, network),
154+
address: utxolib.address.fromOutputScript(out.script, network),
155155
amount: ( new BN(out.value) ).div( TEN.pow(decimals) ).toString()
156156
}));
157157

@@ -166,7 +166,7 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
166166
transaction.ins[i].value = recoveryRequest.inputs[i].amount;
167167
});
168168

169-
const txBuilder = utxoLib.TransactionBuilder.fromTransaction(transaction, network);
169+
const txBuilder = utxolib.TransactionBuilder.fromTransaction(transaction, network);
170170

171171
_.forEach(recoveryRequest.inputs, function(input, i) {
172172

@@ -184,7 +184,7 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
184184
if (BCH_COINS.includes(recoveryRequest.coin)) {
185185
const redeemScript = new Buffer(input.redeemScript, 'hex');
186186
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript,
187-
utxoLib.Transaction.SIGHASH_BITCOINCASHBIP143 | utxoLib.Transaction.SIGHASH_ALL, input.amount);
187+
utxolib.Transaction.SIGHASH_BITCOINCASHBIP143 | utxolib.Transaction.SIGHASH_ALL, input.amount);
188188
// in a Lodash forEach loop, 'return' operates like 'continue' does
189189
// in a regular javascript loop. It finishes this iteration and moves to the next iteration
190190
return;
@@ -193,10 +193,10 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
193193
// Handle Bech32
194194
if (!input.redeemScript) {
195195
const witnessScript = Buffer.from(input.witnessScript, 'hex');
196-
const witnessScriptHash = utxoLib.crypto.sha256(witnessScript);
197-
const prevOutScript = utxoLib.script.witnessScriptHash.output.encode(witnessScriptHash);
196+
const witnessScriptHash = utxolib.crypto.sha256(witnessScript);
197+
const prevOutScript = utxolib.script.witnessScriptHash.output.encode(witnessScriptHash);
198198
txBuilder.sign(i, derivedHDNode.keyPair, prevOutScript,
199-
utxoLib.Transaction.SIGHASH_ALL, input.amount, witnessScript);
199+
utxolib.Transaction.SIGHASH_ALL, input.amount, witnessScript);
200200
return;
201201
}
202202

@@ -205,12 +205,12 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
205205
if (input.witnessScript) {
206206
const witnessScript = new Buffer(input.witnessScript, 'hex');
207207
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript,
208-
utxoLib.Transaction.SIGHASH_ALL, input.amount, witnessScript);
208+
utxolib.Transaction.SIGHASH_ALL, input.amount, witnessScript);
209209
return;
210210
}
211211

212212
// Handle all other requests
213-
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript, utxoLib.Transaction.SIGHASH_ALL, input.amount);
213+
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript, utxolib.Transaction.SIGHASH_ALL, input.amount);
214214
});
215215

216216
return txBuilder.build().toHex();
@@ -421,7 +421,7 @@ const parseKey = co(function *(rawkey, coin, path) {
421421
throw new Error('Invalid mnemonic');
422422
}
423423
const seed = yield bip39.mnemonicToSeed(mnemonic);
424-
let node = utxoLib.HDNode.fromSeedBuffer(seed);
424+
let node = utxolib.HDNode.fromSeedBuffer(seed);
425425
if (path) {
426426
node = node.derivePath(path);
427427
}
@@ -431,7 +431,7 @@ const parseKey = co(function *(rawkey, coin, path) {
431431
}
432432
// if it doesn't have commas, we expect it is an xprv or xlmsecret properly formatted
433433
if (path) {
434-
let node = utxoLib.HDNode.fromPrivateKeyBuffer(Buffer.from(rawkey, 'hex'));
434+
let node = utxolib.HDNode.fromPrivateKeyBuffer(Buffer.from(rawkey, 'hex'));
435435
node = node.derivePath(path);
436436
return node.toBase58();
437437
}

0 commit comments

Comments
 (0)