Code cleaned
This commit is contained in:
parent
8c36b040c0
commit
78c1d40986
1 changed files with 0 additions and 117 deletions
|
|
@ -2567,123 +2567,6 @@ Wallet.prototype.isComplete = function() {
|
||||||
return this.publicKeyRing.isComplete();
|
return this.publicKeyRing.isComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @desc Sign a JSON
|
|
||||||
*
|
|
||||||
* @TODO: THIS WON'T WORK ALLWAYS! JSON.stringify doesn't warants an order
|
|
||||||
* @param {Object} payload - the payload to verify
|
|
||||||
* @return {string} base64 encoded string
|
|
||||||
*/
|
|
||||||
Wallet.prototype.signJson = function(payload) {
|
|
||||||
var key = new bitcore.Key();
|
|
||||||
key.private = new Buffer(this.getMyCopayerIdPriv(), 'hex');
|
|
||||||
key.regenerateSync();
|
|
||||||
var sign = bitcore.Message.sign(JSON.stringify(payload), key);
|
|
||||||
return sign.toString('hex');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @desc Verify that a JSON object is correctly signed
|
|
||||||
*
|
|
||||||
* @TODO: THIS WON'T WORK ALLWAYS! JSON.stringify doesn't warants an order
|
|
||||||
*
|
|
||||||
* @param {string} senderId - a sender's public key, hex encoded
|
|
||||||
* @param {Object} payload - the object to verify
|
|
||||||
* @param {string} signature - a sender's public key, hex encoded
|
|
||||||
* @return {boolean}
|
|
||||||
*/
|
|
||||||
Wallet.prototype.verifySignedJson = function(senderId, payload, signature) {
|
|
||||||
var pubkey = new Buffer(senderId, 'hex');
|
|
||||||
var sign = new Buffer(signature, 'hex');
|
|
||||||
var v = bitcore.Message.verifyWithPubKey(pubkey, JSON.stringify(payload), sign);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @desc Create a HTTP request
|
|
||||||
* @TODO: This shouldn't be a wallet responsibility
|
|
||||||
*/
|
|
||||||
Wallet.request = function(options, callback) {
|
|
||||||
if (_.isString(options)) {
|
|
||||||
options = {
|
|
||||||
uri: options
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
options.method = options.method || 'GET';
|
|
||||||
options.headers = options.headers || {};
|
|
||||||
|
|
||||||
var ret = {
|
|
||||||
success: function(cb) {
|
|
||||||
this._success = cb;
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
error: function(cb) {
|
|
||||||
this._error = cb;
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
_success: function() {;
|
|
||||||
},
|
|
||||||
_error: function(_, err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var method = (options.method || 'GET').toUpperCase();
|
|
||||||
var uri = options.uri || options.url;
|
|
||||||
var req = options;
|
|
||||||
|
|
||||||
req.headers = req.headers || {};
|
|
||||||
req.body = req.body || req.data || {};
|
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open(method, uri, true);
|
|
||||||
|
|
||||||
Object.keys(req.headers).forEach(function(key) {
|
|
||||||
var val = req.headers[key];
|
|
||||||
if (key === 'Content-Length') return;
|
|
||||||
if (key === 'Content-Transfer-Encoding') return;
|
|
||||||
xhr.setRequestHeader(key, val);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (req.responseType) {
|
|
||||||
xhr.responseType = req.responseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.onload = function(event) {
|
|
||||||
var response = xhr.response;
|
|
||||||
var buf = new Uint8Array(response);
|
|
||||||
var headers = {};
|
|
||||||
(xhr.getAllResponseHeaders() || '').replace(
|
|
||||||
/(?:\r?\n|^)([^:\r\n]+): *([^\r\n]+)/g,
|
|
||||||
function($0, $1, $2) {
|
|
||||||
headers[$1.toLowerCase()] = $2;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return ret._success(buf, xhr.status, headers, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onerror = function(event) {
|
|
||||||
var status;
|
|
||||||
if (xhr.status === 0 || !xhr.statusText) {
|
|
||||||
status = 'HTTP Request Error: This endpoint likely does not support cross-origin requests.';
|
|
||||||
} else {
|
|
||||||
status = xhr.statusText;
|
|
||||||
}
|
|
||||||
return ret._error(null, status, null, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (req.body) {
|
|
||||||
xhr.send(req.body);
|
|
||||||
} else {
|
|
||||||
xhr.send(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.getTransactionHistory(function(err, res) {
|
self.getTransactionHistory(function(err, res) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue