2015-11-04 00:53:26 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.services')
|
2015-11-04 01:54:54 -03:00
|
|
|
.factory('hwWallet', function($log, bwcService) {
|
2015-11-04 00:53:26 -03:00
|
|
|
var root = {};
|
|
|
|
|
|
|
|
|
|
// Ledger magic number to get xPub without user confirmation
|
|
|
|
|
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
|
|
|
|
root.UNISIG_ROOTPATH = 44;
|
|
|
|
|
root.MULTISIG_ROOTPATH = 48;
|
|
|
|
|
root.LIVENET_PATH = 0;
|
|
|
|
|
|
|
|
|
|
root._err = function(data) {
|
2015-11-04 01:54:54 -03:00
|
|
|
var msg = 'Hardware Wallet Error: ' + (data.error || data.message || 'unknown');
|
2015-11-04 00:53:26 -03:00
|
|
|
$log.warn(msg);
|
|
|
|
|
return msg;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.getAddressPath = function(isMultisig, account) {
|
|
|
|
|
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH;
|
|
|
|
|
return rootPath + "'/" + root.LIVENET_PATH + "'/" + account + "'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root.getEntropyPath = function(isMultisig, account) {
|
|
|
|
|
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH;
|
2015-11-04 01:54:54 -03:00
|
|
|
var path = root.ENTROPY_INDEX_PATH + rootPath + "'/" + account + "'";
|
2015-11-04 00:53:26 -03:00
|
|
|
return path;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.pubKeyToEntropySource = function(xPubKey) {
|
|
|
|
|
var b = bwcService.getBitcore();
|
|
|
|
|
var x = b.HDPublicKey(xPubKey);
|
|
|
|
|
return x.publicKey.toString();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
});
|