Fix Conflicts:

index.html
This commit is contained in:
Gustavo Cortez 2014-06-02 22:19:15 -03:00
commit 7aebf032ef
16 changed files with 225 additions and 165 deletions

View File

@ -24,7 +24,7 @@ grunt shell --target=dev
Open Copay: Open Copay:
``` ```
node app.js npm start
``` ```
Then visit localhost:3000 in your browser. Then visit localhost:3000 in your browser.
@ -33,16 +33,16 @@ Then visit localhost:3000 in your browser.
## Running copay ## Running copay
To run on a different port: To run on a different port:
``` ```
PORT=3001 node app.js PORT=3001 npm start
``` ```
To open up five different instances to test 3-of-5 multisig with yourself, then run this in 5 different terminals: To open up five different instances to test 3-of-5 multisig with yourself, then run this in 5 different terminals:
``` ```
PORT=3001 node app.js PORT=3001 npm start
PORT=3002 node app.js PORT=3002 npm start
PORT=3003 node app.js PORT=3003 npm start
PORT=3004 node app.js PORT=3004 npm start
PORT=3005 node app.js PORT=3005 npm start
``` ```
To open n different instances more easily, just run: To open n different instances more easily, just run:
@ -51,12 +51,22 @@ n=5
node launch.js $n & node launch.js $n &
``` ```
To require Copay as a module for use within you application:
```js
require('copay').start(3000, function(location) {
console.log('Copay server running at: ' + location);
});
```
## Configuration ## Configuration
Default configuration can be found in the config.js file. Default configuration can be found in the config.js file.
See config.js for more info on configuration options. See config.js for more info on configuration options.
# About Copay # About Copay
General General
@ -140,13 +150,3 @@ Peer Authentication
It is important to note that - except for private keys - *all data* in the wallet is shared with *all members of the wallet*. It is important to note that - except for private keys - *all data* in the wallet is shared with *all members of the wallet*.
Private keys are never shared with anyone and are never sent over the network. There are no *private* messages between Private keys are never shared with anyone and are never sent over the network. There are no *private* messages between
individual members of the wallet. All members of a wallet see everything that happens in that wallet. individual members of the wallet. All members of a wallet see everything that happens in that wallet.

15
app.js
View File

@ -1,12 +1,15 @@
var express=require("express"); var express = require('express');
var http=require("http"); var http = require('http');
var app = express(); var app = express();
var port = process.env.PORT || 3000; app.start = function(port, callback) {
app.set("port", port);
app.set('port', port);
app.use(express.static(__dirname)); app.use(express.static(__dirname));
app.listen(port, function() { app.listen(port, function() {
console.log("Listening at: http://localhost:" + port); callback('http://localhost:' + port);
}); });
};
module.exports = app;

View File

@ -182,7 +182,7 @@
<div class="signin" ng-controller="SigninController"> <div class="signin" ng-controller="SigninController">
<div data-alert class="alert-box info radius" ng-show="loading && !failure"> <div data-alert class="alert-box info radius" ng-show="loading && !failure">
<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i> <i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i>
Authenticating and Looking for peers... Authenticating and looking for peers...
</div> </div>
<div class="alert-box error radius" ng-show="failure"> <div class="alert-box error radius" ng-show="failure">
Oops, we had an error! Looks like you are already connected to this wallet, Oops, we had an error! Looks like you are already connected to this wallet,
@ -753,7 +753,7 @@ on supported browsers please check <a href="http://www.webrtc.org/">http://www.w
<script src="config.js"></script> <script src="config.js"></script>
<script src="js/shell.js"></script>
<script src="lib/angular/angular.min.js"></script> <script src="lib/angular/angular.min.js"></script>
<script src="lib/moment/moment.js"></script> <script src="lib/moment/moment.js"></script>
<script src="lib/angular-moment/angular-moment.js"></script> <script src="lib/angular-moment/angular-moment.js"></script>

View File

@ -59,4 +59,3 @@ angular.module('copay.video', []);
angular.module('copay.import', []); angular.module('copay.import', []);
angular.module('copay.passphrase', []); angular.module('copay.passphrase', []);
angular.module('copay.settings', []); angular.module('copay.settings', []);

View File

@ -6,7 +6,15 @@ angular.module('copay.import').controller('ImportController',
var reader = new FileReader(); var reader = new FileReader();
var _importBackup = function(encryptedObj) { var _importBackup = function(encryptedObj) {
Passphrase.getBase64Async($scope.password, function(passphrase){ Passphrase.getBase64Async($scope.password, function(passphrase){
$rootScope.wallet = walletFactory.fromEncryptedObj(encryptedObj, passphrase); var w = walletFactory.fromEncryptedObj(encryptedObj, passphrase);
if (!w) {
$scope.loading = false;
$rootScope.$flashMessage = { message: 'Wrong password', type: 'error'};
$rootScope.$digest();
return;
}
$rootScope.wallet = w;
controllerUtils.startNetwork($rootScope.wallet); controllerUtils.startNetwork($rootScope.wallet);
}); });
}; };
@ -33,6 +41,7 @@ angular.module('copay.import').controller('ImportController',
var password = form.password.$modelValue; var password = form.password.$modelValue;
if (!backupFile && !backupText) { if (!backupFile && !backupText) {
$scope.loading = false;
$rootScope.$flashMessage = { message: 'Please, select your backup file or paste the text', type: 'error'}; $rootScope.$flashMessage = { message: 'Please, select your backup file or paste the text', type: 'error'};
$scope.loading = false; $scope.loading = false;
return; return;

View File

@ -23,17 +23,15 @@ angular.module('copay.signin').controller('SigninController',
console.log('## Obtaining passphrase...'); console.log('## Obtaining passphrase...');
Passphrase.getBase64Async(password, function(passphrase){ Passphrase.getBase64Async(password, function(passphrase){
console.log('## Done.'); console.log('## Passphrase obtained');
var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase}); var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase});
if (!w) { if (!w) {
$scope.loading = $scope.failure = false; $scope.loading = $scope.failure = false;
$rootScope.$flashMessage = { message: 'Bad password or connection error', type: 'error'}; $rootScope.$flashMessage = { message: 'Wrong password', type: 'error'};
$rootScope.$digest(); $rootScope.$digest();
return; return;
} }
console.log('[signin.js.49]'); //TODO
installStartupHandlers(w); installStartupHandlers(w);
console.log('[signin.js.52]'); //TODO
controllerUtils.startNetwork(w); controllerUtils.startNetwork(w);
}); });
}; };

View File

@ -63,9 +63,7 @@ Wallet.prototype.seedCopayer = function(pubKey) {
Wallet.prototype.connectToAll = function() { Wallet.prototype.connectToAll = function() {
console.log('[Wallet.js.57]'); //TODO
var all = this.publicKeyRing.getAllCopayerIds(); var all = this.publicKeyRing.getAllCopayerIds();
console.log('[Wallet.js.58] connecting'); //TODO console.log('[Wallet.js.58] connecting'); //TODO
this.network.connectToCopayers(all); this.network.connectToCopayers(all);
if (this.seededCopayerId) { if (this.seededCopayerId) {
@ -225,7 +223,7 @@ Wallet.prototype.netStart = function() {
self.emit('openError'); self.emit('openError');
}); });
net.on('error', function() { net.on('error', function() {
self.emit('connectionError'); // Bubble the error self.emit('connectionError');
}); });
net.on('close', function() { net.on('close', function() {
self.emit('close'); self.emit('close');

View File

@ -39,14 +39,11 @@ WalletFactory.prototype.log = function(){
WalletFactory.prototype._checkRead = function(walletId) { WalletFactory.prototype._checkRead = function(walletId) {
var s = this.storage; var s = this.storage;
var ret = var ret =
(
s.get(walletId, 'publicKeyRing') && s.get(walletId, 'publicKeyRing') &&
s.get(walletId, 'txProposals') && s.get(walletId, 'txProposals') &&
s.get(walletId, 'opts') && s.get(walletId, 'opts') &&
s.get(walletId, 'privateKey') s.get(walletId, 'privateKey');
)?true:false; return !!ret;
;
return ret?true:false;
}; };
WalletFactory.prototype.fromObj = function(obj) { WalletFactory.prototype.fromObj = function(obj) {
@ -60,8 +57,9 @@ WalletFactory.prototype.fromObj = function(obj) {
WalletFactory.prototype.fromEncryptedObj = function(base64, password) { WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
this.storage._setPassphrase(password); this.storage._setPassphrase(password);
var walletObj = this.storage.import(base64); var walletObj = this.storage.import(base64);
if (!walletObj) return false;
var w = this.fromObj(walletObj); var w = this.fromObj(walletObj);
w.store(); if (!w) return false;
return w; return w;
}; };
@ -149,7 +147,6 @@ WalletFactory.prototype.open = function(walletId, opts) {
var w = this.read(walletId); var w = this.read(walletId);
if (w) { if (w) {
this._checkVersion(w.version); this._checkVersion(w.version);
w.store(); w.store();

View File

@ -269,7 +269,6 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
self._checkAnyPeer(); self._checkAnyPeer();
}); });
p.on('connection', function(dataConn) { p.on('connection', function(dataConn) {
console.log('### NEW INBOUND CONNECTION %d/%d', self.connectedPeers.length, self.maxPeers); console.log('### NEW INBOUND CONNECTION %d/%d', self.connectedPeers.length, self.maxPeers);
if (self.connectedPeers.length >= self.maxPeers) { if (self.connectedPeers.length >= self.maxPeers) {

View File

@ -3,6 +3,7 @@
var imports = require('soop').imports(); var imports = require('soop').imports();
var id = 0; var id = 0;
function Storage(opts) { function Storage(opts) {
opts = opts || {}; opts = opts || {};
@ -34,11 +35,15 @@ Storage.prototype._encryptObj = function(obj) {
Storage.prototype._decrypt = function(base64) { Storage.prototype._decrypt = function(base64) {
var decryptedStr = null; var decryptedStr = null;
try {
var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase()); var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase());
if (decrypted) if (decrypted)
decryptedStr = decrypted.toString(CryptoJS.enc.Utf8); decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
} catch (e) {
console.log('Error while decrypting ' + base64);
return null;
}
return decryptedStr; return decryptedStr;
}; };
@ -49,18 +54,12 @@ Storage.prototype._decryptObj = function(base64) {
Storage.prototype._read = function(k) { Storage.prototype._read = function(k) {
var ret; var ret;
try {
ret = localStorage.getItem(k); ret = localStorage.getItem(k);
if (ret){ if (!ret) return null;
ret = this._decrypt(ret); ret = this._decrypt(ret);
if (!ret) return null;
ret = ret.toString(CryptoJS.enc.Utf8); ret = ret.toString(CryptoJS.enc.Utf8);
ret = JSON.parse(ret); ret = JSON.parse(ret);
}
} catch (e) {
console.log('Error while decrypting: '+e);
return null;
};
return ret; return ret;
}; };
@ -93,7 +92,6 @@ Storage.prototype._key = function(walletId, k) {
// get value by key // get value by key
Storage.prototype.get = function(walletId, k) { Storage.prototype.get = function(walletId, k) {
var ret = this._read(this._key(walletId, k)); var ret = this._read(this._key(walletId, k));
return ret; return ret;
}; };

View File

@ -62,35 +62,29 @@ angular.module('copay.controllerUtils')
$rootScope.wallet = w; $rootScope.wallet = w;
$location.path('addresses'); $location.path('addresses');
video.setOwnPeer(myPeerID, w, handlePeerVideo); video.setOwnPeer(myPeerID, w, handlePeerVideo);
console.log('# Done ready handler');
}); });
w.on('publicKeyRingUpdated', function(dontDigest) { w.on('publicKeyRingUpdated', function(dontDigest) {
console.log('[start publicKeyRing handler]'); //TODO
root.setSocketHandlers(); root.setSocketHandlers();
root.updateAddressList(); root.updateAddressList();
if (!dontDigest) { if (!dontDigest) {
console.log('[pkr digest]');
$rootScope.$digest(); $rootScope.$digest();
console.log('[done digest]');
} }
}); });
w.on('txProposalsUpdated', function(dontDigest) { w.on('txProposalsUpdated', function(dontDigest) {
root.updateTxs({onlyPending:true}); root.updateTxs({onlyPending:true});
root.updateBalance(function(){ root.updateBalance(function(){
if (!dontDigest) { if (!dontDigest) {
console.log('[txp digest]');
$rootScope.$digest(); $rootScope.$digest();
console.log('[done digest]');
} }
}); });
}); });
w.on('openError', root.onErrorDigest); w.on('openError', root.onErrorDigest);
w.on('connectionError', root.onErrorDigest);
w.on('connect', function(peerID) { w.on('connect', function(peerID) {
if (peerID) { if (peerID) {
video.callPeer(peerID, handlePeerVideo); video.callPeer(peerID, handlePeerVideo);
} }
console.log('[digest]');
$rootScope.$digest(); $rootScope.$digest();
}); });
w.on('disconnect', function(peerID) { w.on('disconnect', function(peerID) {
@ -129,7 +123,6 @@ angular.module('copay.controllerUtils')
$rootScope.availableBalance = safeBalance; $rootScope.availableBalance = safeBalance;
root.updateAddressList(); root.updateAddressList();
$rootScope.updatingBalance = false; $rootScope.updatingBalance = false;
console.log('Done updating balance.'); //TODO
return cb?cb():null; return cb?cb():null;
}); });
}; };
@ -145,7 +138,6 @@ angular.module('copay.controllerUtils')
var inT = w.getTxProposals().sort(function(t1, t2) { return t1.createdTs < t2.createdTs }); var inT = w.getTxProposals().sort(function(t1, t2) { return t1.createdTs < t2.createdTs });
var txs = []; var txs = [];
console.log('[START LOOP]'); //TODO
inT.forEach(function(i, index){ inT.forEach(function(i, index){
if (opts.skip && (index < opts.skip[0] || index >= opts.skip[1])) { if (opts.skip && (index < opts.skip[0] || index >= opts.skip[1])) {
return txs.push(null); return txs.push(null);

60
js/shell.js Normal file
View File

@ -0,0 +1,60 @@
/*
** copay-shell integration
*/
(function() {
/*
** This is a monkey patch for when Copay is running from
** within Copay-Shell (atom-shell). Since the renderer (the frontend)
** receives context from Node.js, we get a `module.exports` contruct
** available to us. Because of this, some libs (specifically Moment.js)
** attempt to assume their CommonJS form and bind to this. This causes
** there to be no references in the window to these libs, so let's trick
** the renderer into thinking that we are _not_ in a CommonJS environment.
*/
if (typeof module !== 'undefined') module = { exports: null };
// are we running in copay shell?
if (process && process.type === 'renderer') initCopayShellBindings();
function controller(name) {
return angular.element(
document.querySelectorAll(
'[ng-controller="' + name + '"], [data-ng-controller="' + name + '"]'
)
).scope();
};
function initCopayShellBindings() {
var ipc = require('ipc');
ipc.on('address:create', function(data) {
location.href = '#/addresses';
controller('AddressesController').newAddr();
});
ipc.on('transactions:send', function(data) {
location.href = '#/send';
});
ipc.on('transactions:all', function(data) {
location.href = '#/transactions';
controller('TransactionsController').show();
});
ipc.on('transactions:pending', function(data) {
location.href = '#/transactions';
controller('TransactionsController').show(true);
});
ipc.on('backup:download', function(data) {
});
ipc.on('backup:email', function(data) {
});
};
})();

View File

@ -26,7 +26,6 @@ var DEFAULT_PORT = process.env.DEFAULT_PORT || 3000;
for (var i=0; i<N; i++) { for (var i=0; i<N; i++) {
var port =(i+DEFAULT_PORT); var port =(i+DEFAULT_PORT);
console.log('Simulating copayer #'+(i+1)+' at http://localhost:'+port); console.log('Simulating copayer #'+(i+1)+' at http://localhost:'+port);
var command = 'PORT='+port+' node app.js &' var command = 'PORT='+port+' npm start &'
exec(command, puts); exec(command, puts);
} }

View File

@ -17,7 +17,9 @@
"bugs": { "bugs": {
"url": "https://github.com/bitpay/copay/issues" "url": "https://github.com/bitpay/copay/issues"
}, },
"main": "app.js",
"scripts": { "scripts": {
"start": "node server.js",
"test": "mocha" "test": "mocha"
}, },
"homepage": "https://github.com/bitpay/copay", "homepage": "https://github.com/bitpay/copay",

6
server.js Normal file
View File

@ -0,0 +1,6 @@
var server = require('./app');
var port = process.env.PORT || 3000;
server.start(port, function(loc){
console.log('Listening at: ' + loc);
});