1
1
const Promise = require ( 'bluebird' ) ;
2
2
const co = Promise . coroutine ;
3
- const utxoLib = require ( '@bitgo/utxo-lib' ) ;
3
+ const utxolib = require ( '@bitgo/utxo-lib' ) ;
4
4
const accountLib = require ( '@bitgo/account-lib' ) ;
5
5
const statics = require ( '@bitgo/statics' ) ;
6
6
const fs = require ( 'fs' ) ;
@@ -14,18 +14,18 @@ const bitgojs = require('bitgo');
14
14
let bitgo ;
15
15
16
16
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
29
29
} ;
30
30
31
31
const coinDecimals = {
@@ -90,7 +90,7 @@ const getHDNodeAndVerify = function(xprv, expectedXpub) {
90
90
let node ;
91
91
92
92
try {
93
- node = utxoLib . HDNode . fromBase58 ( xprv ) ;
93
+ node = utxolib . HDNode . fromBase58 ( xprv ) ;
94
94
} catch ( e ) {
95
95
throw new Error ( 'invalid private key' ) ;
96
96
}
@@ -148,10 +148,10 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
148
148
}
149
149
150
150
const txHex = getTransactionHexFromRequest ( recoveryRequest ) ;
151
- const transaction = utxoLib . Transaction . fromHex ( txHex , network ) ;
151
+ const transaction = utxolib . Transaction . fromHex ( txHex , network ) ;
152
152
153
153
const outputs = transaction . outs . map ( out => ( {
154
- address : utxoLib . address . fromOutputScript ( out . script , network ) ,
154
+ address : utxolib . address . fromOutputScript ( out . script , network ) ,
155
155
amount : ( new BN ( out . value ) ) . div ( TEN . pow ( decimals ) ) . toString ( )
156
156
} ) ) ;
157
157
@@ -166,7 +166,7 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
166
166
transaction . ins [ i ] . value = recoveryRequest . inputs [ i ] . amount ;
167
167
} ) ;
168
168
169
- const txBuilder = utxoLib . TransactionBuilder . fromTransaction ( transaction , network ) ;
169
+ const txBuilder = utxolib . TransactionBuilder . fromTransaction ( transaction , network ) ;
170
170
171
171
_ . forEach ( recoveryRequest . inputs , function ( input , i ) {
172
172
@@ -184,7 +184,7 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
184
184
if ( BCH_COINS . includes ( recoveryRequest . coin ) ) {
185
185
const redeemScript = new Buffer ( input . redeemScript , 'hex' ) ;
186
186
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 ) ;
188
188
// in a Lodash forEach loop, 'return' operates like 'continue' does
189
189
// in a regular javascript loop. It finishes this iteration and moves to the next iteration
190
190
return ;
@@ -193,10 +193,10 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
193
193
// Handle Bech32
194
194
if ( ! input . redeemScript ) {
195
195
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 ) ;
198
198
txBuilder . sign ( i , derivedHDNode . keyPair , prevOutScript ,
199
- utxoLib . Transaction . SIGHASH_ALL , input . amount , witnessScript ) ;
199
+ utxolib . Transaction . SIGHASH_ALL , input . amount , witnessScript ) ;
200
200
return ;
201
201
}
202
202
@@ -205,12 +205,12 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
205
205
if ( input . witnessScript ) {
206
206
const witnessScript = new Buffer ( input . witnessScript , 'hex' ) ;
207
207
txBuilder . sign ( i , derivedHDNode . keyPair , redeemScript ,
208
- utxoLib . Transaction . SIGHASH_ALL , input . amount , witnessScript ) ;
208
+ utxolib . Transaction . SIGHASH_ALL , input . amount , witnessScript ) ;
209
209
return ;
210
210
}
211
211
212
212
// 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 ) ;
214
214
} ) ;
215
215
216
216
return txBuilder . build ( ) . toHex ( ) ;
@@ -421,7 +421,7 @@ const parseKey = co(function *(rawkey, coin, path) {
421
421
throw new Error ( 'Invalid mnemonic' ) ;
422
422
}
423
423
const seed = yield bip39 . mnemonicToSeed ( mnemonic ) ;
424
- let node = utxoLib . HDNode . fromSeedBuffer ( seed ) ;
424
+ let node = utxolib . HDNode . fromSeedBuffer ( seed ) ;
425
425
if ( path ) {
426
426
node = node . derivePath ( path ) ;
427
427
}
@@ -431,7 +431,7 @@ const parseKey = co(function *(rawkey, coin, path) {
431
431
}
432
432
// if it doesn't have commas, we expect it is an xprv or xlmsecret properly formatted
433
433
if ( path ) {
434
- let node = utxoLib . HDNode . fromPrivateKeyBuffer ( Buffer . from ( rawkey , 'hex' ) ) ;
434
+ let node = utxolib . HDNode . fromPrivateKeyBuffer ( Buffer . from ( rawkey , 'hex' ) ) ;
435
435
node = node . derivePath ( path ) ;
436
436
return node . toBase58 ( ) ;
437
437
}
0 commit comments