Skip to content

Commit

Permalink
Allow for asynchronous signing
Browse files Browse the repository at this point in the history
Do not error when api version=2 and no pin is provided. Instead,
return the object to sign.
  • Loading branch information
patricklodder committed Oct 24, 2014
1 parent a2d06ad commit 566f8da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 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
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 566f8da

Please sign in to comment.