updated
This commit is contained in:
commit
a1e5246727
44 changed files with 3762 additions and 365 deletions
|
|
@ -33,7 +33,8 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
$scope.addresses.push({
|
||||
'address': addrinfo.addressStr,
|
||||
'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.addressStr] : 0,
|
||||
'isChange': addrinfo.isChange
|
||||
'isChange': addrinfo.isChange,
|
||||
'owned': addrinfo.owned
|
||||
});
|
||||
}
|
||||
$scope.selectedAddr = $scope.addresses[0];
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('BackupController',
|
||||
function($scope, $rootScope, $location, $window, $timeout, $modal, backupService, walletFactory, controllerUtils) {
|
||||
$scope.title = 'Backup';
|
||||
$scope.title = 'Settings';
|
||||
|
||||
$scope.download = function() {
|
||||
backupService.download($rootScope.wallet);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('FooterController', function($rootScope, $sce, $scope, $http) {
|
||||
|
||||
$scope.networkName = config.networkName;
|
||||
|
||||
if (config.themes && Array.isArray(config.themes) && config.themes[0]) {
|
||||
$scope.themes = config.themes;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
|||
'icon': 'fi-arrow-right',
|
||||
'link': '#/send'
|
||||
}, {
|
||||
'title': 'Backup',
|
||||
'icon': 'fi-archive',
|
||||
'title': 'Settings',
|
||||
'icon': 'fi-wrench',
|
||||
'link': '#/backup'
|
||||
}];
|
||||
|
||||
|
|
@ -71,7 +71,9 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
|||
|
||||
$rootScope.$watch('txAlertCount', function(txAlertCount) {
|
||||
if (txAlertCount && txAlertCount > 0) {
|
||||
notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount);
|
||||
notification.info('New Transaction', ($rootScope.txAlertCount == 1) ?
|
||||
'You have a pending transaction proposal' :
|
||||
'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -75,10 +75,9 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
}
|
||||
|
||||
var backupFile = $scope.file;
|
||||
var backupText = form.backupText.$modelValue;
|
||||
var password = form.password.$modelValue;
|
||||
|
||||
if (!backupFile && !backupText) {
|
||||
if (!backupFile) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', 'Please, select your backup file or paste the file contents');
|
||||
$scope.loading = false;
|
||||
|
|
@ -87,8 +86,6 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
|
||||
if (backupFile) {
|
||||
reader.readAsBinaryString(backupFile);
|
||||
} else {
|
||||
_importBackup(backupText);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
return flag;
|
||||
};
|
||||
|
||||
if ($rootScope.pendingPayment) {
|
||||
var pp = $rootScope.pendingPayment;
|
||||
$scope.address = pp.address;
|
||||
var amount = pp.amount / config.unitToSatoshi * 100000000;
|
||||
$scope.amount = amount;
|
||||
}
|
||||
|
||||
// Detect protocol
|
||||
$scope.isHttp = ($window.location.protocol.indexOf('http') === 0);
|
||||
|
||||
|
|
@ -61,6 +68,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$scope.loading = false;
|
||||
});
|
||||
}
|
||||
$rootScope.pendingPayment = null;
|
||||
});
|
||||
|
||||
// reset fields
|
||||
|
|
@ -250,7 +258,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.topAmount = function(form) {
|
||||
$scope.amount = $scope.getAvailableAmount();
|
||||
$scope.amount = $scope.getAvailableAmount();
|
||||
form.amount.$pristine = false;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ angular.module('copayApp.controllers').controller('SettingsController',
|
|||
$scope.networkHost = config.network.host;
|
||||
$scope.networkPort = config.network.port;
|
||||
$scope.networkSecure = config.network.secure || false;
|
||||
$scope.disableVideo = typeof config.disableVideo === undefined ? true : config.disableVideo;
|
||||
$scope.disableVideo = typeof config.disableVideo === undefined ? true : config.disableVideo;
|
||||
|
||||
$scope.unitOpts = [{
|
||||
name: 'Satoshis (100,000,000 satoshis = 1BTC)',
|
||||
|
|
@ -73,6 +73,8 @@ angular.module('copayApp.controllers').controller('SettingsController',
|
|||
unitToSatoshi: $scope.selectedUnit.value,
|
||||
}));
|
||||
|
||||
$window.location.href = $window.location.origin + $window.location.pathname;
|
||||
var target = ($window.location.origin !== 'null' ? $window.location.origin : '') + $window.location.pathname;
|
||||
|
||||
$window.location.href = target;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ angular.module('copayApp.controllers').controller('SigninController',
|
|||
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
|
||||
$scope.openPassword = '';
|
||||
|
||||
if ($rootScope.pendingPayment) {
|
||||
notification.info('Login Required', 'Please open wallet to complete payment');
|
||||
}
|
||||
|
||||
$scope.open = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
notification.error('Error', 'Please enter the required fields');
|
||||
|
|
|
|||
17
js/controllers/uriPayment.js
Normal file
17
js/controllers/uriPayment.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('UriPaymentController', function($rootScope, $scope, $routeParams, $timeout, $location) {
|
||||
var data = decodeURIComponent($routeParams.data);
|
||||
$rootScope.pendingPayment = copay.Structure.parseBitcoinURI($routeParams.data);
|
||||
|
||||
$scope.protocol = $rootScope.pendingPayment.protocol;
|
||||
$scope.address = $rootScope.pendingPayment.address;
|
||||
$scope.amount = $rootScope.pendingPayment.amount;
|
||||
$scope.message = $rootScope.pendingPayment.message;
|
||||
|
||||
$timeout(function() {
|
||||
$location.path('signin');
|
||||
}, 1000);
|
||||
|
||||
|
||||
});
|
||||
|
|
@ -13,7 +13,7 @@ angular.module('copayApp.directives')
|
|||
link: function(scope, elem, attrs, ctrl) {
|
||||
var validator = function(value) {
|
||||
var a = new Address(value);
|
||||
ctrl.$setValidity('validAddress', a.isValid());
|
||||
ctrl.$setValidity('validAddress', a.isValid() && a.network().name === config.networkName);
|
||||
return value;
|
||||
};
|
||||
|
||||
|
|
@ -29,8 +29,7 @@ angular.module('copayApp.directives')
|
|||
restrict: 'A',
|
||||
link: function(scope, element, attrs, ctrl) {
|
||||
setTimeout(function() {
|
||||
scope.$apply(function() {
|
||||
});
|
||||
scope.$apply(function() {});
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,6 +17,14 @@ angular.module('copayApp.filters', [])
|
|||
return false;
|
||||
};
|
||||
})
|
||||
.filter('removeEmpty', function() {
|
||||
return function(elements) {
|
||||
// Hide empty addresses from other copayers
|
||||
return elements.filter(function(e) {
|
||||
return e.owned || e.balance > 0;
|
||||
});
|
||||
}
|
||||
})
|
||||
.filter('limitAddress', function() {
|
||||
return function(elements, showAll) {
|
||||
if (elements.length <= 1 || showAll) {
|
||||
|
|
|
|||
|
|
@ -1,29 +1,56 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var preconditions = require('preconditions').singleton();
|
||||
var Structure = require('./Structure');
|
||||
|
||||
function AddressIndex(opts) {
|
||||
opts = opts || {};
|
||||
this.walletId = opts.walletId;
|
||||
|
||||
this.cosigner = opts.cosigner
|
||||
this.changeIndex = opts.changeIndex || 0;
|
||||
this.receiveIndex = opts.receiveIndex || 0;
|
||||
|
||||
if (typeof this.cosigner === 'undefined') {
|
||||
this.cosigner = Structure.SHARED_INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
AddressIndex.init = function(totalCopayers) {
|
||||
preconditions.shouldBeNumber(totalCopayers);
|
||||
var indexes = [new AddressIndex()];
|
||||
for (var i = 0 ; i < totalCopayers ; i++) {
|
||||
indexes.push(new AddressIndex({cosigner: i}));
|
||||
}
|
||||
return indexes;
|
||||
}
|
||||
|
||||
AddressIndex.fromList = function(indexes) {
|
||||
return indexes.map(function(i) { return AddressIndex.fromObj(i); });
|
||||
}
|
||||
|
||||
AddressIndex.fromObj = function(data) {
|
||||
if (data instanceof AddressIndex) {
|
||||
throw new Error('bad data format: Did you use .toObj()?');
|
||||
}
|
||||
var ret = new AddressIndex(data);
|
||||
return ret;
|
||||
return new AddressIndex(data);
|
||||
};
|
||||
|
||||
AddressIndex.serialize = function(indexes) {
|
||||
return indexes.map(function(i) { return i.toObj(); });
|
||||
}
|
||||
|
||||
AddressIndex.update = function(shared, totalCopayers) {
|
||||
var indexes = this.init(totalCopayers);
|
||||
indexes[0].changeIndex = shared.changeIndex;
|
||||
indexes[0].receiveIndex = shared.receiveIndex;
|
||||
return this.serialize(indexes);
|
||||
};
|
||||
|
||||
AddressIndex.prototype.toObj = function() {
|
||||
return {
|
||||
walletId: this.walletId,
|
||||
cosigner: this.cosigner,
|
||||
changeIndex: this.changeIndex,
|
||||
receiveIndex: this.receiveIndex,
|
||||
receiveIndex: this.receiveIndex
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -34,10 +61,10 @@ AddressIndex.prototype.checkRange = function(index, isChange) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
AddressIndex.prototype.getChangeIndex = function() {
|
||||
return this.changeIndex;
|
||||
};
|
||||
|
||||
AddressIndex.prototype.getReceiveIndex = function() {
|
||||
return this.receiveIndex;
|
||||
};
|
||||
|
|
@ -51,6 +78,9 @@ AddressIndex.prototype.increment = function(isChange) {
|
|||
};
|
||||
|
||||
AddressIndex.prototype.merge = function(inAddressIndex) {
|
||||
preconditions.shouldBeObject(inAddressIndex)
|
||||
.checkArgument(this.cosigner == inAddressIndex.cosigner);
|
||||
|
||||
var hasChanged = false;
|
||||
|
||||
// Indexes
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ function PrivateKey(opts) {
|
|||
var init = opts.extendedPrivateKeyString || this.network.name;
|
||||
this.bip = opts.HK || new HK(init);
|
||||
this.privateKeyCache = opts.privateKeyCache || {};
|
||||
this.publicHex = this.deriveBIP45Branch().eckey.public.toString('hex');
|
||||
};
|
||||
|
||||
PrivateKey.prototype.getId = function() {
|
||||
|
|
@ -101,21 +102,21 @@ PrivateKey.prototype.getForPath = function(path) {
|
|||
return wk;
|
||||
};
|
||||
|
||||
PrivateKey.prototype.get = function(index, isChange) {
|
||||
var path = Structure.FullBranch(index, isChange);
|
||||
PrivateKey.prototype.get = function(index, isChange, cosigner) {
|
||||
var path = Structure.FullBranch(index, isChange, cosigner);
|
||||
return this.getForPath(path);
|
||||
};
|
||||
|
||||
PrivateKey.prototype.getAll = function(receiveIndex, changeIndex) {
|
||||
PrivateKey.prototype.getAll = function(receiveIndex, changeIndex, cosigner) {
|
||||
if (typeof receiveIndex === 'undefined' || typeof changeIndex === 'undefined')
|
||||
throw new Error('Invalid parameters');
|
||||
|
||||
var ret = [];
|
||||
for (var i = 0; i < receiveIndex; i++) {
|
||||
ret.push(this.get(i, false));
|
||||
ret.push(this.get(i, false, cosigner));
|
||||
}
|
||||
for (var i = 0; i < changeIndex; i++) {
|
||||
ret.push(this.get(i, true));
|
||||
ret.push(this.get(i, true, cosigner));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ function PublicKeyRing(opts) {
|
|||
|
||||
this.copayersHK = opts.copayersHK || [];
|
||||
|
||||
this.indexes = AddressIndex.fromObj(opts.indexes) || new AddressIndex(opts);
|
||||
this.indexes = opts.indexes ? AddressIndex.fromList(opts.indexes)
|
||||
: AddressIndex.init(this.totalCopayers);
|
||||
|
||||
this.publicKeysCache = opts.publicKeysCache || {};
|
||||
this.nicknameFor = opts.nicknameFor || {};
|
||||
|
|
@ -36,6 +37,12 @@ PublicKeyRing.fromObj = function(data) {
|
|||
if (data instanceof PublicKeyRing) {
|
||||
throw new Error('bad data format: Did you use .toObj()?');
|
||||
}
|
||||
|
||||
// Support old indexes schema
|
||||
if (!Array.isArray(data.indexes)) {
|
||||
data.indexes = AddressIndex.update(data.indexes, data.totalCopayers);
|
||||
}
|
||||
|
||||
var ret = new PublicKeyRing(data);
|
||||
|
||||
for (var k in data.copayersExtPubKeys) {
|
||||
|
|
@ -51,7 +58,7 @@ PublicKeyRing.prototype.toObj = function() {
|
|||
networkName: this.network.name,
|
||||
requiredCopayers: this.requiredCopayers,
|
||||
totalCopayers: this.totalCopayers,
|
||||
indexes: this.indexes.toObj(),
|
||||
indexes: AddressIndex.serialize(this.indexes),
|
||||
|
||||
copayersExtPubKeys: this.copayersHK.map(function(b) {
|
||||
return b.extendedPublicKeyString();
|
||||
|
|
@ -136,10 +143,10 @@ PublicKeyRing.prototype.addCopayer = function(newEpk, nickname) {
|
|||
return newEpk;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
||||
PublicKeyRing.prototype.getPubKeys = function(index, isChange, cosigner) {
|
||||
this._checkKeys();
|
||||
|
||||
var path = Structure.Branch(index, isChange);
|
||||
var path = Structure.Branch(index, isChange, cosigner);
|
||||
var pubKeys = this.publicKeysCache[path];
|
||||
if (!pubKeys) {
|
||||
pubKeys = [];
|
||||
|
|
@ -162,20 +169,29 @@ PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
|||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getRedeemScript = function(index, isChange) {
|
||||
var pubKeys = this.getPubKeys(index, isChange);
|
||||
PublicKeyRing.prototype.getRedeemScript = function(index, isChange, cosigner) {
|
||||
var pubKeys = this.getPubKeys(index, isChange, cosigner);
|
||||
var script = Script.createMultisig(this.requiredCopayers, pubKeys);
|
||||
return script;
|
||||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getAddress = function(index, isChange) {
|
||||
var script = this.getRedeemScript(index, isChange);
|
||||
PublicKeyRing.prototype.getAddress = function(index, isChange, id) {
|
||||
var cosigner = this.getCosigner(id);
|
||||
var script = this.getRedeemScript(index, isChange, cosigner);
|
||||
var address = Address.fromScript(script, this.network.name);
|
||||
this.addressToPath[address.toString()] = Structure.FullBranch(index, isChange);
|
||||
this.addressToPath[address.toString()] = Structure.FullBranch(index, isChange, cosigner);
|
||||
return address;
|
||||
};
|
||||
|
||||
// Overloaded to receive a PubkeyString or a consigner index
|
||||
PublicKeyRing.prototype.getIndex = function(id) {
|
||||
var cosigner = this.getCosigner(id);
|
||||
var index = this.indexes.filter(function(i) { return i.cosigner == cosigner });
|
||||
if (index.length != 1) throw new Error('no index for cosigner');
|
||||
return index[0];
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.pathForAddress = function(address) {
|
||||
var path = this.addressToPath[address];
|
||||
if (!path) throw new Error('Couldn\'t find path for address ' + address);
|
||||
|
|
@ -183,17 +199,19 @@ PublicKeyRing.prototype.pathForAddress = function(address) {
|
|||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange) {
|
||||
var addr = this.getAddress(index, isChange);
|
||||
PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange, pubkey) {
|
||||
var cosigner = this.getCosigner(pubkey);
|
||||
var addr = this.getAddress(index, isChange, cosigner);
|
||||
return Script.createP2SH(addr.payload()).getBuffer().toString('hex');
|
||||
};
|
||||
|
||||
//generate a new address, update index.
|
||||
PublicKeyRing.prototype.generateAddress = function(isChange) {
|
||||
PublicKeyRing.prototype.generateAddress = function(isChange, pubkey) {
|
||||
isChange = !!isChange;
|
||||
var index = isChange ? this.indexes.getChangeIndex() : this.indexes.getReceiveIndex();
|
||||
var ret = this.getAddress(index, isChange);
|
||||
this.indexes.increment(isChange);
|
||||
var addrIndex = this.getIndex(pubkey);
|
||||
var index = isChange ? addrIndex.getChangeIndex() : addrIndex.getReceiveIndex();
|
||||
var ret = this.getAddress(index, isChange, addrIndex.cosigner);
|
||||
addrIndex.increment(isChange);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -203,28 +221,58 @@ PublicKeyRing.prototype.getAddresses = function(opts) {
|
|||
});
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
||||
PublicKeyRing.prototype.getCosigner = function(pubKey) {
|
||||
if (typeof pubKey == 'undefined') return Structure.SHARED_INDEX;
|
||||
if (typeof pubKey == 'number') return pubKey;
|
||||
|
||||
var sorted = this.copayersHK.map(function(h, i){
|
||||
return h.eckey.public.toString('hex');
|
||||
}).sort(function(h1, h2){ return h1.localeCompare(h2); });
|
||||
|
||||
var index = sorted.indexOf(pubKey);
|
||||
if (index == -1) throw new Error('no public key in ring');
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) {
|
||||
var ret = [];
|
||||
var self = this;
|
||||
var cosigner = pubkey && this.getCosigner(pubkey);
|
||||
this.indexes.forEach(function(index) {
|
||||
ret = ret.concat(self.getAddressesInfoForIndex(index, opts, cosigner));
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, cosigner) {
|
||||
opts = opts || {};
|
||||
|
||||
var isOwned = index.cosigner == Structure.SHARED_INDEX
|
||||
|| index.cosigner == cosigner;
|
||||
|
||||
var ret = [];
|
||||
if (!opts.excludeChange) {
|
||||
for (var i = 0; i < this.indexes.getChangeIndex(); i++) {
|
||||
var a = this.getAddress(i, true);
|
||||
for (var i = 0; i < index.changeIndex; i++) {
|
||||
var a = this.getAddress(i, true, index.cosigner);
|
||||
ret.unshift({
|
||||
address: this.getAddress(i, true),
|
||||
address: a,
|
||||
addressStr: a.toString(),
|
||||
isChange: true
|
||||
isChange: true,
|
||||
owned: isOwned
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts.excludeMain) {
|
||||
for (var i = 0; i < this.indexes.getReceiveIndex(); i++) {
|
||||
var a = this.getAddress(i, false);
|
||||
for (var i = 0; i < index.receiveIndex; i++) {
|
||||
var a = this.getAddress(i, false, index.cosigner);
|
||||
ret.unshift({
|
||||
address: a,
|
||||
addressStr: a.toString(),
|
||||
isChange: false
|
||||
isChange: false,
|
||||
owned: isOwned
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -235,7 +283,7 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
|||
// TODO this could be cached
|
||||
PublicKeyRing.prototype._addScriptMap = function(map, path) {
|
||||
var p = Structure.indicesForPath(path);
|
||||
var script = this.getRedeemScript(p.index, p.isChange);
|
||||
var script = this.getRedeemScript(p.index, p.isChange, p.cosigner);
|
||||
map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
|
||||
};
|
||||
|
||||
|
|
@ -303,17 +351,25 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
};
|
||||
|
||||
PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
|
||||
var hasChanged = false;
|
||||
|
||||
this._checkInPKR(inPKR, ignoreId);
|
||||
|
||||
if (this.indexes.merge(inPKR.indexes))
|
||||
hasChanged = true;
|
||||
var hasChanged = false;
|
||||
hasChanged |= this.mergeIndexes(inPKR.indexes);
|
||||
hasChanged |= this._mergePubkeys(inPKR);
|
||||
|
||||
if (this._mergePubkeys(inPKR))
|
||||
hasChanged = true;
|
||||
|
||||
return hasChanged;
|
||||
return !!hasChanged;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.mergeIndexes = function(indexes) {
|
||||
var self = this;
|
||||
var hasChanged = false;
|
||||
|
||||
indexes.forEach(function(theirs) {
|
||||
var mine = self.getIndex(theirs.cosigner);
|
||||
hasChanged |= mine.merge(theirs);
|
||||
});
|
||||
|
||||
return !!hasChanged
|
||||
}
|
||||
|
||||
module.exports = require('soop')(PublicKeyRing);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ Structure.indicesForPath = function(path) {
|
|||
return {
|
||||
isChange: s[3] === '1',
|
||||
index: parseInt(s[4]),
|
||||
cosigner: parseInt(s[2])
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -50,4 +51,23 @@ Structure.MAX_NON_HARDENED = MAX_NON_HARDENED;
|
|||
Structure.SHARED_INDEX = SHARED_INDEX;
|
||||
Structure.ID_INDEX = ID_INDEX;
|
||||
|
||||
Structure.parseBitcoinURI = function(uri) {
|
||||
var ret = {};
|
||||
var data = decodeURIComponent(uri);
|
||||
var splitDots = data.split(':');
|
||||
ret.protocol = splitDots[0];
|
||||
data = splitDots[1];
|
||||
var splitQuestion = data.split('?');
|
||||
ret.address = splitQuestion[0];
|
||||
var search = splitQuestion[1];
|
||||
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
||||
function(key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value);
|
||||
});
|
||||
ret.amount = parseFloat(data.amount);
|
||||
ret.message = data.message;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Structure);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ var buffertools = bitcore.buffertools;
|
|||
var Builder = bitcore.TransactionBuilder;
|
||||
var SecureRandom = bitcore.SecureRandom;
|
||||
var Base58Check = bitcore.Base58.base58Check;
|
||||
var Address = bitcore.Address;
|
||||
|
||||
var AddressIndex = require('./AddressIndex');
|
||||
var PublicKeyRing = require('./PublicKeyRing');
|
||||
|
|
@ -38,12 +39,6 @@ function Wallet(opts) {
|
|||
this.id = opts.id || Wallet.getRandomId();
|
||||
this.name = opts.name;
|
||||
|
||||
// Renew token every 24hs
|
||||
if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) {
|
||||
this.token = opts.token;
|
||||
this.tokenTime = opts.tokenTime;
|
||||
}
|
||||
|
||||
this.verbose = opts.verbose;
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
|
|
@ -51,6 +46,7 @@ function Wallet(opts) {
|
|||
this.registeredPeerIds = [];
|
||||
this.addressBook = opts.addressBook || {};
|
||||
this.backupOffered = opts.backupOffered || false;
|
||||
this.publicKey = this.privateKey.publicHex;
|
||||
}
|
||||
|
||||
Wallet.parent = EventEmitter;
|
||||
|
|
@ -81,8 +77,8 @@ Wallet.prototype.connectToAll = function() {
|
|||
|
||||
Wallet.prototype._handleIndexes = function(senderId, data, isInbound) {
|
||||
this.log('RECV INDEXES:', data);
|
||||
var inIndexes = AddressIndex.fromObj(data.indexes);
|
||||
var hasChanged = this.publicKeyRing.indexes.merge(inIndexes);
|
||||
var inIndexes = AddressIndex.fromList(data.indexes);
|
||||
var hasChanged = this.publicKeyRing.mergeIndexes(inIndexes);
|
||||
if (hasChanged) {
|
||||
this.emit('publicKeyRingUpdated');
|
||||
this.store();
|
||||
|
|
@ -218,11 +214,6 @@ Wallet.prototype._optsToObj = function() {
|
|||
version: this.version,
|
||||
};
|
||||
|
||||
if (this.token) {
|
||||
obj.token = this.token;
|
||||
obj.tokenTime = new Date().getTime();
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
|
@ -255,6 +246,7 @@ Wallet.decodeSecret = function(secretB) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype._lockIncomming = function() {
|
||||
this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds());
|
||||
};
|
||||
|
|
@ -279,7 +271,6 @@ Wallet.prototype.netStart = function(callback) {
|
|||
var startOpts = {
|
||||
copayerId: myId,
|
||||
privkey: myIdPriv,
|
||||
token: self.token,
|
||||
maxPeers: self.totalCopayers
|
||||
};
|
||||
|
||||
|
|
@ -289,12 +280,10 @@ Wallet.prototype.netStart = function(callback) {
|
|||
|
||||
net.start(startOpts, function() {
|
||||
self.emit('ready', net.getPeer());
|
||||
self.token = net.peer.options.token;
|
||||
setTimeout(function() {
|
||||
self.emit('publicKeyRingUpdated', true);
|
||||
self.scheduleConnect();
|
||||
self.emit('txProposalsUpdated');
|
||||
self.store();
|
||||
}, 10);
|
||||
});
|
||||
};
|
||||
|
|
@ -332,7 +321,8 @@ Wallet.prototype.getRegisteredPeerIds = function() {
|
|||
var pid = this.network.peerFromCopayer(cid);
|
||||
this.registeredPeerIds.push({
|
||||
peerId: pid,
|
||||
nick: this.publicKeyRing.nicknameForCopayer(cid)
|
||||
nick: this.publicKeyRing.nicknameForCopayer(cid),
|
||||
index: i,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -377,8 +367,6 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
|||
|
||||
Wallet.prototype.toEncryptedObj = function() {
|
||||
var walletObj = this.toObj();
|
||||
delete walletObj.opts.token;
|
||||
delete walletObj.opts.tokenTime;
|
||||
return this.storage.export(walletObj);
|
||||
};
|
||||
|
||||
|
|
@ -434,11 +422,12 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
|||
});
|
||||
};
|
||||
Wallet.prototype.sendIndexes = function(recipients) {
|
||||
this.log('### INDEXES TO:', recipients || 'All', this.publicKeyRing.indexes.toObj());
|
||||
var indexes = AddressIndex.serialize(this.publicKeyRing.indexes);
|
||||
this.log('### INDEXES TO:', recipients || 'All', indexes);
|
||||
|
||||
this.network.send(recipients, {
|
||||
type: 'indexes',
|
||||
indexes: this.publicKeyRing.indexes.toObj(),
|
||||
indexes: indexes,
|
||||
walletId: this.id,
|
||||
});
|
||||
};
|
||||
|
|
@ -457,7 +446,7 @@ Wallet.prototype.getName = function() {
|
|||
};
|
||||
|
||||
Wallet.prototype._doGenerateAddress = function(isChange) {
|
||||
return this.publicKeyRing.generateAddress(isChange);
|
||||
return this.publicKeyRing.generateAddress(isChange, this.publicKey);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -511,7 +500,6 @@ Wallet.prototype.sign = function(ntxid, cb) {
|
|||
if (cb) cb(false);
|
||||
}
|
||||
|
||||
var pkr = self.publicKeyRing;
|
||||
var keys = self.privateKey.getForPaths(txp.inputChainPaths);
|
||||
|
||||
var b = txp.builder;
|
||||
|
|
@ -583,7 +571,7 @@ Wallet.prototype.getAddressesStr = function(opts) {
|
|||
};
|
||||
|
||||
Wallet.prototype.getAddressesInfo = function(opts) {
|
||||
return this.publicKeyRing.getAddressesInfo(opts);
|
||||
return this.publicKeyRing.getAddressesInfo(opts, this.publicKey);
|
||||
};
|
||||
|
||||
Wallet.prototype.addressIsOwn = function(addrStr, opts) {
|
||||
|
|
@ -691,7 +679,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
opts = opts || {};
|
||||
|
||||
var amountSat = bignum(amountSatStr);
|
||||
|
||||
preconditions.checkArgument(new Address(toAddress).network().name === this.getNetworkName());
|
||||
if (!pkr.isComplete()) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
}
|
||||
|
|
@ -749,31 +737,44 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
|
||||
Wallet.prototype.updateIndexes = function(callback) {
|
||||
var self = this;
|
||||
var start = self.publicKeyRing.indexes.changeIndex;
|
||||
self.log('Updating indexes...');
|
||||
self.indexDiscovery(start, true, 20, function(err, changeIndex) {
|
||||
|
||||
var tasks = this.publicKeyRing.indexes.map(function(index) {
|
||||
return function(callback) {
|
||||
self.updateIndex(index, callback);
|
||||
};
|
||||
});
|
||||
|
||||
async.parallel(tasks, function(err) {
|
||||
if (err) callback(err);
|
||||
self.log('Indexes updated');
|
||||
self.emit('publicKeyRingUpdated');
|
||||
self.store();
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
Wallet.prototype.updateIndex = function(index, callback) {
|
||||
var self = this;
|
||||
var SCANN_WINDOW = 20;
|
||||
self.indexDiscovery(index.changeIndex, true, index.cosigner, SCANN_WINDOW, function(err, changeIndex) {
|
||||
if (err) return callback(err);
|
||||
if (changeIndex != -1)
|
||||
self.publicKeyRing.indexes.changeIndex = changeIndex + 1;
|
||||
index.changeIndex = changeIndex + 1;
|
||||
|
||||
start = self.publicKeyRing.indexes.receiveIndex;
|
||||
self.indexDiscovery(start, false, 20, function(err, receiveIndex) {
|
||||
self.indexDiscovery(index.receiveIndex, false, index.cosigner, SCANN_WINDOW, function(err, receiveIndex) {
|
||||
if (err) return callback(err);
|
||||
if (receiveIndex != -1)
|
||||
self.publicKeyRing.indexes.receiveIndex = receiveIndex + 1;
|
||||
|
||||
self.log('Indexes updated');
|
||||
self.emit('publicKeyRingUpdated');
|
||||
self.store();
|
||||
index.receiveIndex = receiveIndex + 1;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Wallet.prototype.deriveAddresses = function(index, amout, isChange) {
|
||||
Wallet.prototype.deriveAddresses = function(index, amout, isChange, cosigner) {
|
||||
var ret = new Array(amout);
|
||||
for (var i = 0; i < amout; i++) {
|
||||
ret[i] = this.publicKeyRing.getAddress(index + i, isChange).toString();
|
||||
ret[i] = this.publicKeyRing.getAddress(index + i, isChange, cosigner).toString();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -781,7 +782,7 @@ Wallet.prototype.deriveAddresses = function(index, amout, isChange) {
|
|||
// This function scans the publicKeyRing branch starting at index @start and reports the index with last activity,
|
||||
// using a scan window of @gap. The argument @change defines the branch to scan: internal or external.
|
||||
// Returns -1 if no activity is found in range.
|
||||
Wallet.prototype.indexDiscovery = function(start, change, gap, cb) {
|
||||
Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
|
||||
var scanIndex = start;
|
||||
var lastActive = -1;
|
||||
var hasActivity = false;
|
||||
|
|
@ -791,7 +792,7 @@ Wallet.prototype.indexDiscovery = function(start, change, gap, cb) {
|
|||
function _do(next) {
|
||||
// Optimize window to minimize the derivations.
|
||||
var scanWindow = (lastActive == -1) ? gap : gap - (scanIndex - lastActive) + 1;
|
||||
var addresses = self.deriveAddresses(scanIndex, scanWindow, change);
|
||||
var addresses = self.deriveAddresses(scanIndex, scanWindow, change, cosigner);
|
||||
self.blockchain.checkActivity(addresses, function(err, actives) {
|
||||
if (err) throw err;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ Network.prototype.cleanUp = function() {
|
|||
this.privkey = null; //TODO: hide privkey in a closure
|
||||
this.key = null;
|
||||
this.copayerId = null;
|
||||
this.signingKey = null;
|
||||
this.allowedCopayerIds = null;
|
||||
this.isInboundPeerAuth = [];
|
||||
this.copayerForPeer = {};
|
||||
|
|
@ -346,6 +345,7 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
|
||||
if (!self.criticalError && self.tries < self.reconnectAttempts) {
|
||||
self.tries++;
|
||||
self.opts.token = util.sha256(self.peerId).toString('hex');
|
||||
self.peer = new Peer(self.peerId, self.opts);
|
||||
self.started = true;
|
||||
self._setupPeerHandlers(openCallback);
|
||||
|
|
|
|||
|
|
@ -26,10 +26,6 @@ angular
|
|||
templateUrl: 'addresses.html',
|
||||
validate: true
|
||||
})
|
||||
.when('/join/:id', {
|
||||
templateUrl: 'join.html',
|
||||
validate: true
|
||||
})
|
||||
.when('/transactions', {
|
||||
templateUrl: 'transactions.html',
|
||||
validate: true
|
||||
|
|
@ -49,6 +45,9 @@ angular
|
|||
.when('/unsupported', {
|
||||
templateUrl: 'unsupported.html'
|
||||
})
|
||||
.when('/uri_payment/:data', {
|
||||
templateUrl: 'uri_payment.html'
|
||||
})
|
||||
.otherwise({
|
||||
templateUrl: '404.html'
|
||||
});
|
||||
|
|
@ -64,7 +63,6 @@ angular
|
|||
})
|
||||
.run(function($rootScope, $location) {
|
||||
$rootScope.$on('$routeChangeStart', function(event, next, current) {
|
||||
|
||||
if (!util.supports.data) {
|
||||
$location.path('unsupported');
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
var bitcore = require('bitcore');
|
||||
|
||||
angular.module('copayApp.services')
|
||||
.factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, Socket, video) {
|
||||
.factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, Socket, video, uriHandler) {
|
||||
var root = {};
|
||||
|
||||
root.getVideoMutedStatus = function(copayer) {
|
||||
|
|
@ -43,20 +43,15 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.installStartupHandlers = function(wallet, $scope) {
|
||||
wallet.on('serverError', function(msg) {
|
||||
notification.error('PeerJS Error', 'There was an error connecting to the PeerJS server.' + (msg || 'Check you settings and Internet connection.'));
|
||||
root.onErrorDigest($scope);
|
||||
$location.path('addresses');
|
||||
});
|
||||
wallet.on('connectionError', function() {
|
||||
var message = "Looks like you are already connected to this wallet, please logout and try importing it again.";
|
||||
notification.error('PeerJS Error', message);
|
||||
root.onErrorDigest($scope);
|
||||
});
|
||||
wallet.on('serverError', function() {
|
||||
var message = 'The PeerJS server is not responding, please try again';
|
||||
notification.error('PeerJS Error', message);
|
||||
root.onErrorDigest($scope);
|
||||
wallet.on('serverError', function(m) {
|
||||
var message = m || 'The PeerJS server is not responding, please try again';
|
||||
$location.path('addresses');
|
||||
root.onErrorDigest($scope, message);
|
||||
});
|
||||
wallet.on('ready', function() {
|
||||
$scope.loading = false;
|
||||
|
|
@ -64,6 +59,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.setupRootVariables = function() {
|
||||
uriHandler.register();
|
||||
$rootScope.unitName = config.unitName;
|
||||
$rootScope.txAlertCount = 0;
|
||||
$rootScope.insightError = 0;
|
||||
|
|
@ -102,7 +98,11 @@ angular.module('copayApp.services')
|
|||
});
|
||||
w.on('ready', function(myPeerID) {
|
||||
$rootScope.wallet = w;
|
||||
$location.path('addresses');
|
||||
if ($rootScope.pendingPayment) {
|
||||
$location.path('send');
|
||||
} else {
|
||||
$location.path('addresses');
|
||||
}
|
||||
if (!config.disableVideo)
|
||||
video.setOwnPeer(myPeerID, w, handlePeerVideo);
|
||||
});
|
||||
|
|
|
|||
11
js/services/uriHandler.js
Normal file
11
js/services/uriHandler.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
var UriHandler = function() {};
|
||||
|
||||
UriHandler.prototype.register = function() {
|
||||
var base = window.location.origin + '/';
|
||||
var url = base + '#/uri_payment/%s';
|
||||
// navigator.registerProtocolHandler('bitcoin', url, 'Copay');
|
||||
};
|
||||
|
||||
angular.module('copayApp.services').value('uriHandler', new UriHandler());
|
||||
15
js/shell.js
15
js/shell.js
|
|
@ -12,7 +12,7 @@
|
|||
** the renderer into thinking that we are _not_ in a CommonJS environment.
|
||||
*/
|
||||
if (typeof module !== 'undefined') module = {
|
||||
exports: null
|
||||
exports: false
|
||||
};
|
||||
|
||||
// are we running in copay shell?
|
||||
|
|
@ -39,22 +39,12 @@
|
|||
var ipc = require('ipc');
|
||||
var clipb = require('clipboard');
|
||||
|
||||
// atom shell forces to implement the clipboard on our own - thanks obama.
|
||||
// atom shell forces to implement the clipboard (on osx) on our own - thanks obama.
|
||||
|
||||
Mousetrap.stopCallback = function() {
|
||||
return false
|
||||
};
|
||||
|
||||
Mousetrap.bind('ctrl+c', function(e) {
|
||||
clipb.writeText(window.getSelection().toString());
|
||||
});
|
||||
|
||||
Mousetrap.bind('ctrl+v', function(e) {
|
||||
if (document.activeElement) {
|
||||
document.activeElement.value = clipb.readText();
|
||||
}
|
||||
});
|
||||
|
||||
Mousetrap.bind('command+c', function(e) {
|
||||
clipb.writeText(window.getSelection().toString());
|
||||
});
|
||||
|
|
@ -62,6 +52,7 @@
|
|||
Mousetrap.bind('command+v', function(e) {
|
||||
if (document.activeElement) {
|
||||
document.activeElement.value = clipb.readText();
|
||||
document.activeElement.dispatchEvent(new Event('change'));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue