Skip to content

Commit

Permalink
Merge pull request #5 from BlockIo/1.0.2-dev
Browse files Browse the repository at this point in the history
1.0.2: Allow for asynchronous signing
  • Loading branch information
patricklodder committed Oct 24, 2014
2 parents a2d06ad + 69817ca commit 508c4d8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
15 changes: 9 additions & 6 deletions lib/block_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ BlockIo.prototype._withdraw = function (method, path, args, cb) {
if (!args || typeof(args) !== 'object') args = {};

// check for pin
var pin;
var pin = null;
var pinSupplied = (typeof(args.pin) !== 'undefined');
if (!pinSupplied && typeof(this.pin) === 'undefined') {
return cb(new Error('Missing "pin", please supply as argument or at initialization time.'));
} else {

if (pinSupplied || typeof(this.pin) != 'undefined')
pin = pinSupplied ? args.pin : this.pin;
}


// add pin to args for v1, remove for v2;
if (this.version === 1) {
if (this.version == 1) {
if (!pin) return cb(new Error('Missing "pin", please supply as argument or at initialization time.'));
args.pin = pin;
} else {
delete args.pin;
Expand All @@ -90,6 +90,9 @@ BlockIo.prototype._withdraw = function (method, path, args, cb) {
if (!res.data.encrypted_passphrase || !res.data.encrypted_passphrase.passphrase)
return cb(e, res);

// if no pin was supplied, return the response for signing asynchronously
if (!pin) return cb(e, res);

// If we get here, Block.io's asking us to provide some client-side signatures, let's get to it
var encrypted_passphrase = res.data.encrypted_passphrase.passphrase;
var aesKey = self.aesKey || helper.pinToKey(pin);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name" : "block_io",
"description" : "Block.io API wrapper for node.js",
"keywords" : [ "block.io", "block_io", "bitcoin", "litecoin", "dogecoin", "wallet" ],
"version" : "1.0.1",
"version" : "1.0.2",
"preferGlobal" : false,
"homepage" : "https://github.com/BlockIo/block_io-nodejs",
"author" : "Patrick Lodder <[email protected]> (https://github.com/patricklodder)",
Expand Down
39 changes: 39 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,44 @@ spec.addBatch({
)
});


if (VERSION == 1) spec.addBatch({
"withdraw_from_address (without PIN, v1)": {
topic: function () {
client.pin = null;
client.aesKey = null;
client.withdraw_from_address({
from_labels: cache.lazy('fromAddress'),
payment_address: cache.lazy('newAddress'),
amount: genericHelpers.calcWithdrawalAmount,
}, this.callback);
},
"must return an error": function (err, res) {
assert.instanceOf(err, Error);
}
}
});

if (VERSION > 1) spec.addBatch({
"withdraw_from_address (without PIN, > v1)": genericHelpers.makeMethodCase(
client,
'withdraw_from_label',
{
from_labels: cache.lazy('fromLabel'),
payment_address: cache.lazy('newAddress'),
amount: genericHelpers.calcWithdrawalAmount,
},
{
"must return a transaction to sign": function (err, res, r) {
assert.isObject(res);
assert.isObject(res.data);
assert.isString(res.data.reference_id)
assert.isObject(res.data.encrypted_passphrase)
assert.isArray(res.data.inputs);
}
}
)
});

if (genericHelpers.checkEnv()) spec.export(module);

0 comments on commit 508c4d8

Please sign in to comment.