@@ -324,140 +324,6 @@ export class API extends EventEmitter {
324
324
this . request . setCredentials ( this . credentials ) ;
325
325
}
326
326
327
- /**
328
- * Import from Mnemonics (language autodetected)
329
- * Can throw an error if mnemonic is invalid
330
- * Will try compilant and non-compliantDerivation
331
- *
332
- * @param {String } BIP39 words
333
- * @param {Object } opts
334
- * @param {String } opts.coin - default 'btc'
335
- * @param {String } opts.network - default 'livenet'
336
- * @param {String } opts.passphrase
337
- * @param {Number } opts.account - default 0
338
- * @param {String } opts.derivationStrategy - default 'BIP44'
339
- * @param {String } opts.entropySourcePath - Only used if the wallet was created on a HW wallet, in which that private keys was not available for all the needed derivations
340
- * @param {String } opts.walletPrivKey - if available, walletPrivKey for encrypting metadata
341
- */
342
- importFromMnemonic ( words , opts , cb ) {
343
- $ . checkState ( false , 'not supported' ) ;
344
-
345
- log . debug ( 'Importing from Mnemonic' ) ;
346
-
347
- opts = opts || { } ;
348
- opts . coin = opts . coin || 'btc' ;
349
-
350
- function derive ( nonCompliantDerivation ?, useLegacyCoinType ?) {
351
- return Credentials . fromMnemonic ( opts . coin , opts . network || 'livenet' , words , opts . passphrase , opts . account || 0 , opts . derivationStrategy || Constants . DERIVATION_STRATEGIES . BIP44 , {
352
- nonCompliantDerivation,
353
- entropySourcePath : opts . entropySourcePath ,
354
- walletPrivKey : opts . walletPrivKey ,
355
- useLegacyCoinType,
356
- } ) ;
357
- }
358
-
359
- try {
360
- this . credentials = derive ( ) ;
361
- } catch ( e ) {
362
- log . info ( 'Mnemonic error:' , e ) ;
363
- return cb ( new Errors . INVALID_BACKUP ) ;
364
- }
365
- this . request . setCredentials ( this . credentials ) ;
366
- // TODO BWC => ts
367
- _import ( function ( err , ret ) {
368
- if ( ! err ) return cb ( null , ret ) ;
369
- if ( err instanceof Errors . INVALID_BACKUP ) return cb ( err ) ;
370
- if ( err instanceof Errors . NOT_AUTHORIZED || err instanceof Errors . WALLET_DOES_NOT_EXIST ) {
371
-
372
- var altCredentials ;
373
- // Only BTC wallets can be nonCompliantDerivation
374
- switch ( opts . coin ) {
375
- case 'btc' :
376
- // try using nonCompliantDerivation
377
- altCredentials = derive ( true ) ;
378
- break ;
379
- case 'bch' :
380
- // try using 0 as coin for BCH (old wallets)
381
- altCredentials = derive ( false , true ) ;
382
- break ;
383
- default :
384
- return cb ( err ) ;
385
- }
386
-
387
- if ( altCredentials . xPubKey . toString ( ) == this . credentials . xPubKey . toString ( ) )
388
- return cb ( err ) ;
389
-
390
- this . credentials = altCredentials ;
391
- this . request . setCredentials ( this . credentials ) ;
392
- return this . _import ( cb ) ;
393
- }
394
- return cb ( err ) ;
395
- } ) ;
396
- }
397
-
398
- /*
399
- * Import from extended private key
400
- *
401
- * @param {String } xPrivKey
402
- * @param {String } opts.coin - default 'btc'
403
- * @param {Number } opts.account - default 0
404
- * @param {String } opts.derivationStrategy - default 'BIP44'
405
- * @param {String } opts.compliantDerivation - default 'true'
406
- * @param {String } opts.walletPrivKey - if available, walletPrivKey for encrypting metadata
407
- * @param {Callback } cb - The callback that handles the response. It returns a flag indicating that the wallet is imported.
408
- */
409
- importFromExtendedPrivateKey ( xPrivKey , opts , cb ) {
410
- $ . checkState ( false , 'not supported' ) ;
411
- log . debug ( 'Importing from Extended Private Key' ) ;
412
-
413
- if ( ! cb ) {
414
- cb = opts ;
415
- opts = { } ;
416
- log . warn ( 'DEPRECATED WARN: importFromExtendedPrivateKey should receive 3 parameters.' ) ;
417
- }
418
-
419
- try {
420
- this . credentials = Credentials . fromExtendedPrivateKey ( opts . coin || 'btc' , xPrivKey , opts . account || 0 , opts . derivationStrategy || Constants . DERIVATION_STRATEGIES . BIP44 , opts ) ;
421
- } catch ( e ) {
422
- log . info ( 'xPriv error:' , e ) ;
423
- return cb ( new Errors . INVALID_BACKUP ) ;
424
- }
425
-
426
- this . request . setCredentials ( this . credentials ) ;
427
- this . _import ( cb ) ;
428
- }
429
-
430
- /**
431
- * Import from Extended Public Key
432
- *
433
- * @param {String } xPubKey
434
- * @param {String } source - A name identifying the source of the xPrivKey
435
- * @param {String } entropySourceHex - A HEX string containing pseudo-random data, that can be deterministically derived from the xPrivKey, and should not be derived from xPubKey.
436
- * @param {Object } opts
437
- * @param {String } opts.coin - default 'btc'
438
- * @param {Number } opts.account - default 0
439
- * @param {String } opts.derivationStrategy - default 'BIP44'
440
- * @param {String } opts.compliantDerivation - default 'true'
441
- */
442
- importFromExtendedPublicKey ( xPubKey , source , entropySourceHex , opts , cb ) {
443
- $ . checkState ( false , 'not supported' ) ;
444
- $ . checkArgument ( arguments . length == 5 , 'DEPRECATED: should receive 5 arguments' ) ;
445
- $ . checkArgument ( _ . isUndefined ( opts ) || _ . isObject ( opts ) ) ;
446
- $ . shouldBeFunction ( cb ) ;
447
-
448
- opts = opts || { } ;
449
- log . debug ( 'Importing from Extended Private Key' ) ;
450
- try {
451
- this . credentials = Credentials . fromExtendedPublicKey ( opts . coin || 'btc' , xPubKey , source , entropySourceHex , opts . account || 0 , opts . derivationStrategy || Constants . DERIVATION_STRATEGIES . BIP44 , opts ) ;
452
- } catch ( e ) {
453
- log . info ( 'xPriv error:' , e ) ;
454
- return cb ( new Errors . INVALID_BACKUP ) ;
455
- }
456
-
457
- this . request . setCredentials ( this . credentials ) ;
458
- this . _import ( cb ) ;
459
- }
460
-
461
327
decryptBIP38PrivateKey ( encryptedPrivateKeyBase58 , passphrase , opts , cb ) {
462
328
var Bip38 = require ( 'bip38' ) ;
463
329
var bip38 = new Bip38 ( ) ;
0 commit comments