Browse Source

Documentation

activeAddress
Ivan Socolsky 10 years ago
parent
commit
a7f1c4f2bb
  1. 3
      .gitignore
  2. 58
      lib/server.js
  3. 3
      package.json

3
.gitignore

@ -27,4 +27,5 @@ node_modules
# Users Environment Variables
.lock-wscript
*.swp
*.swp
out/

58
lib/server.js

@ -11,12 +11,26 @@ var Storage = require('./storage');
var Wallet = require('./model/wallet');
var Copayer = require('./model/copayer');
/**
* Creates an instance of the Copay server.
* @constructor
*/
function CopayServer(opts) {
opts = opts || {};
this.storage = new Storage(opts);
};
/**
* Creates a new wallet.
* @param {object} opts
* @param {string} opts.id - The wallet id.
* @param {string} opts.name - The wallet name.
* @param {number} opts.m - Required copayers.
* @param {number} opts.n - Total copayers.
* @param {string} opts.pubKey - Public key to verify copayers joining have access to the wallet secret.
* @param {string} [opts.network = 'livenet'] - The Bitcoin network for this wallet.
*/
CopayServer.prototype.createWallet = function (opts, cb) {
var self = this;
@ -37,7 +51,14 @@ CopayServer.prototype.createWallet = function (opts, cb) {
});
};
CopayServer.prototype.getWallet = function (opts, cb) {
/**
* Retrieves a wallet from storage.
* @param {object} opts
* @param {string} opts.id - The wallet id.
* @param {truthy} opts.includeCopayers - Fetch wallet along with list of copayers.
* @returns {Object} wallet
*/
CopayServer.prototype.getWallet = function (opts, cb) {
var self = this;
self.storage.fetchWallet(opts.id, function (err, wallet) {
@ -54,8 +75,16 @@ CopayServer.prototype.getWallet = function (opts, cb) {
});
};
CopayServer.prototype.joinWallet = function (opts, cb) {
/**
* Joins a wallet in creation.
* @param {object} opts
* @param {string} opts.walletId - The wallet id.
* @param {string} opts.id - The copayer id.
* @param {string} opts.name - The copayer name.
* @param {number} opts.xPubKey - Extended Public Key for this copayer.
* @param {number} opts.xPubKeySignature - Signature of xPubKey using the wallet pubKey.
*/
CopayServer.prototype.joinWallet = function (opts, cb) {
var self = this;
Lock.get(opts.walletId, function (lock) {
@ -169,14 +198,6 @@ CopayServer.prototype._doCreateTx = function (opts, cb) {
return tx;
};
// opts = {
// copayerId,
// walletId,
// toAddress,
// amount, // in Satoshi
// message,
// otToken, // one time random token generated by the client and signed to avoid replay attacks
// utxos: [], // optional (not yet implemented)
// requestSignature, // S(toAddress + amount + otToken) using this copayers privKey
// // using this signature, the server can
// };
@ -185,7 +206,20 @@ CopayServer.prototype._doCreateTx = function (opts, cb) {
// ntxid,
// rawTx,
// };
/**
* Creates a new transaction proposal.
* @param {object} opts
* @param {string} opts.walletId - The wallet id.
* @param {string} opts.copayerId - The wallet id.
* @param {truthy} opts.otToken - A one-time token used to avoid reply attacks.
* @param {string} opts.toAddress - Destination address.
* @param {number} opts.amount - Amount to transfer in satoshi.
* @param {string} opts.message - A message to attach to this transaction.
* @param {string} opts.requestSignature - Signature of the request (toAddress + amount + otToken).
* @returns {Object} result
* @returns {Object} result.ntxid - Id of the transaction proposal.
* @returns {Object} result.rawTx - Raw transaction.
*/
CopayServer.prototype.createTx = function (opts, cb) {
// Client generates a unique token and signs toAddress + amount + token.
// This way we authenticate + avoid replay attacks.

3
package.json

@ -30,7 +30,8 @@
"chai": "^1.9.1",
"mocha": "^1.18.2",
"sinon": "^1.10.3",
"memdown": "^1.0.0"
"memdown": "^1.0.0",
"jsdoc": "^3.3.0"
},
"scripts": {
"start": "node server.js"

Loading…
Cancel
Save