mirror of https://github.com/BTCPrivate/copay.git
support xPrivKey seeds
This commit is contained in:
parent
b712874c17
commit
f1f4e5cfaf
|
@ -47,8 +47,8 @@
|
|||
</div>
|
||||
|
||||
<div class="row m20t" ng-show="!wordsC.mnemonicWords">
|
||||
<div class="columns size-14 text-gray" translate>
|
||||
The wallet seed not available on this device. You can still export the wallet to backup it.
|
||||
<div class="columns size-14 text-gray text-center" translate>
|
||||
Wallet seed not available. You can still export it from Advanced > Export .
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
||||
};
|
||||
|
||||
this.externalIndexValues = lodash.range(0,ledger.MAX_SLOT);
|
||||
this.externalIndexValues = lodash.range(0, ledger.MAX_SLOT);
|
||||
$scope.externalIndex = 0;
|
||||
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
|
||||
$scope.totalCopayers = defaults.wallet.totalCopayers;
|
||||
|
@ -62,13 +62,18 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
};
|
||||
var setSeed = form.setSeed.$modelValue;
|
||||
if (setSeed) {
|
||||
opts.mnemonic = form.privateKey.$modelValue;
|
||||
var words = form.privateKey.$modelValue;
|
||||
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||
opts.extendedPrivateKey = words;
|
||||
} else {
|
||||
opts.mnemonic = words;
|
||||
}
|
||||
opts.passphrase = form.passphrase.$modelValue;
|
||||
} else {
|
||||
opts.passphrase = form.createPassphrase.$modelValue;
|
||||
}
|
||||
|
||||
if (setSeed && !opts.mnemonic) {
|
||||
if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
|
||||
this.error = gettext('Please enter the wallet seed');
|
||||
return;
|
||||
}
|
||||
|
@ -90,7 +95,7 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
}
|
||||
};
|
||||
|
||||
this._create = function (opts) {
|
||||
this._create = function(opts) {
|
||||
self.loading = true;
|
||||
$timeout(function() {
|
||||
profileService.createWallet(opts, function(err, secret, walletId) {
|
||||
|
@ -104,9 +109,8 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
});
|
||||
}
|
||||
else {
|
||||
if ( ( opts.mnemonic && opts.n==1) || opts.externalSource ) {
|
||||
} else {
|
||||
if (opts.n == 1 && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
} else {
|
||||
go.walletHome();
|
||||
|
@ -122,11 +126,9 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
if (what && what == 'my-name') {
|
||||
this.hideWalletName = true;
|
||||
this.hideTabs = true;
|
||||
}
|
||||
else if (what && what == 'wallet-name'){
|
||||
} else if (what && what == 'wallet-name') {
|
||||
this.hideTabs = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.hideWalletName = false;
|
||||
this.hideTabs = false;
|
||||
}
|
||||
|
|
|
@ -63,11 +63,32 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
};
|
||||
|
||||
|
||||
var _importExtendedPrivateKey = function(xPrivKey) {
|
||||
self.loading = true;
|
||||
|
||||
$timeout(function() {
|
||||
profileService.importExtendedPrivateKey(xPrivKey, function(err, walletId) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
return $timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||
go.walletHome();
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
|
||||
|
||||
var _importMnemonic = function(words, opts) {
|
||||
self.loading = true;
|
||||
|
||||
$timeout(function() {
|
||||
profileService.importWalletMnemonic(words, opts, function(err, walletId) {
|
||||
profileService.importMnemonic(words, opts, function(err, walletId) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
|
@ -140,7 +161,11 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
|
||||
if (!words) {
|
||||
this.error = gettext('Please enter the seed words');
|
||||
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||
return _importExtendedPrivateKey(words)
|
||||
} else {
|
||||
|
||||
console.log('[import.js.167]', words.indexOf(' '), words.indexOf('prv')); //TODO
|
||||
var wordList = words.split(/ /).filter(function(v) {
|
||||
return v.length > 0;
|
||||
});
|
||||
|
|
|
@ -737,7 +737,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
};
|
||||
|
||||
self.showErrorPopup = function (msg, cb) {
|
||||
self.showErrorPopup = function(msg, cb) {
|
||||
$log.warn('Showing err popup:' + msg);
|
||||
self.showAlert = {
|
||||
msg: msg,
|
||||
|
@ -1015,7 +1015,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.needsBackup = false;
|
||||
storageService.setBackupFlag(walletId, function() {
|
||||
addressService.expireAddress(walletId, function(err) {
|
||||
$timeout(function() {
|
||||
self.startScan(walletId);
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1108,7 +1110,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
|
||||
$rootScope.$on('Local/ShowAlert', function(event, msg, cb) {
|
||||
self.showErrorPopup(msg,cb);
|
||||
self.showErrorPopup(msg, cb);
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
|
||||
|
|
|
@ -158,13 +158,18 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
|
||||
var setSeed = form.setSeed.$modelValue;
|
||||
if (setSeed) {
|
||||
opts.mnemonic = form.privateKey.$modelValue;
|
||||
var words = form.privateKey.$modelValue;
|
||||
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||
opts.extendedPrivateKey = words;
|
||||
} else {
|
||||
opts.mnemonic = words;
|
||||
}
|
||||
opts.passphrase = form.passphrase.$modelValue;
|
||||
} else {
|
||||
opts.passphrase = form.createPassphrase.$modelValue;
|
||||
}
|
||||
|
||||
if (setSeed && !opts.mnemonic) {
|
||||
if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
|
||||
this.error = gettext('Please enter the wallet seed');
|
||||
return;
|
||||
}
|
||||
|
@ -197,7 +202,7 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
}
|
||||
$timeout(function() {
|
||||
var fc = profileService.focusedClient;
|
||||
if ( ( opts.mnemonic || opts.externalSource ) && fc.isComplete()) {
|
||||
if ( fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
|
||||
$rootScope.$emit('Local/WalletImported', fc.credentials.walletId);
|
||||
} else {
|
||||
go.walletHome();
|
||||
|
|
|
@ -177,6 +177,13 @@ angular.module('copayApp.services')
|
|||
$log.info(ex);
|
||||
return cb(gettext('Could not create: Invalid wallet seed'));
|
||||
}
|
||||
} else if (opts.extendedPrivateKey) {
|
||||
try {
|
||||
walletClient.seedFromExtendedPrivateKey(opts.extendedPrivateKey);
|
||||
} catch (ex) {
|
||||
$log.warn(ex);
|
||||
return cb(gettext('Could not create using the specified extended private key'));
|
||||
}
|
||||
} else if (opts.extendedPublicKey) {
|
||||
try {
|
||||
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource);
|
||||
|
@ -344,7 +351,21 @@ angular.module('copayApp.services')
|
|||
root._addWalletClient(walletClient, cb);
|
||||
};
|
||||
|
||||
root.importWalletMnemonic = function(words, opts, cb) {
|
||||
root.importExtendedPrivateKey = function(xPrivKey, cb) {
|
||||
var walletClient = bwcService.getClient();
|
||||
$log.debug('Importing Wallet xPrivKey');
|
||||
|
||||
walletClient.importFromExtendedPrivateKey(xPrivKey, function(err) {
|
||||
if (err)
|
||||
return bwsError.cb(err, gettext('Could not import'), cb);
|
||||
|
||||
root._addWalletClient(walletClient, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
root.importMnemonic = function(words, opts, cb) {
|
||||
var walletClient = bwcService.getClient();
|
||||
$log.debug('Importing Wallet Mnemonic');
|
||||
|
||||
|
|
Loading…
Reference in New Issue