Wallet/src/js/services/hwWallet.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-11-04 00:53:26 -03:00
'use strict';
angular.module('copayApp.services')
.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/";
2016-12-05 17:33:46 -05:00
root.M = 'm/';
2015-11-04 00:53:26 -03:00
root.UNISIG_ROOTPATH = 44;
root.MULTISIG_ROOTPATH = 48;
root.LIVENET_PATH = 0;
2016-12-05 17:33:46 -05:00
root.TESTNET_PATH = 1;
2015-11-04 00:53:26 -03:00
root._err = function(data) {
var msg = data.error || data.message || 'unknown';
return msg;
2015-11-04 00:53:26 -03:00
};
2015-11-10 20:05:05 -03:00
root.getRootPath = function(device, isMultisig, account) {
2016-12-05 17:33:46 -05:00
var path;
if (isMultisig) {
path = root.MULTISIG_ROOTPATH;
} else {
if (device == 'ledger' && account > 0) {
path = root.MULTISIG_ROOTPATH;
} else {
path = root.UNISIG_ROOTPATH;
}
}
if (device == 'intelTEE') {
path = root.M + path;
}
return path;
2015-11-10 20:05:05 -03:00
};
2016-12-05 17:33:46 -05:00
root.getAddressPath = function(device, isMultisig, account, network) {
network = network || 'livenet';
var networkPath = root.LIVENET_PATH;
if (network == 'testnet') {
networkPath = root.TESTNET_PATH;
}
return root.getRootPath(device, isMultisig, account) + "'/" + networkPath + "'/" + account + "'";
};
2015-11-04 00:53:26 -03:00
2015-11-10 20:05:05 -03:00
root.getEntropyPath = function(device, isMultisig, account) {
2016-12-05 17:33:46 -05:00
var path = root.ENTROPY_INDEX_PATH;
if (isMultisig) {
path = path + "48'/"
} else {
path = path + "44'/"
}
2015-11-10 20:05:05 -03:00
// Old ledger wallet compat
2016-12-05 17:33:46 -05:00
if (device == 'ledger' && account == 0) {
return path + "0'/";
}
if (device == 'intelTEE') {
path = root.M + path;
}
2015-11-10 20:05:05 -03:00
2016-12-05 17:33:46 -05:00
return path + account + "'";
2015-11-04 00:53:26 -03:00
};
root.pubKeyToEntropySource = function(xPubKey) {
var b = bwcService.getBitcore();
var x = b.HDPublicKey(xPubKey);
return x.publicKey.toString();
};
return root;
});