From 9096fc4928d910b8dfd8485dbcfc616d26f120df Mon Sep 17 00:00:00 2001 From: Sagiv Ofek Date: Fri, 22 Aug 2014 20:14:17 -0400 Subject: [PATCH] allowing sign keys to be strings no need to pass array of one element to sign a transaction, you can simply pass the private key string (one or more separated by commas) and convert it to array. make user's life easier :) --- lib/TransactionBuilder.js | 6 ++++-- test/test.TransactionBuilder.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/TransactionBuilder.js b/lib/TransactionBuilder.js index d4b60d6..fb50d48 100644 --- a/lib/TransactionBuilder.js +++ b/lib/TransactionBuilder.js @@ -744,8 +744,9 @@ fnToSign[Script.TX_SCRIPTHASH] = TransactionBuilder.prototype._signScriptHash; // sign // ---- // Signs a transaction. -// `keys`: an array of strings representing private keys to sign the -// transaction in WIF private key format OR bitcore's `WalletKey` objects +// `keys`: an array of strings representing private keys to sign the transaction in WIF private key format +// OR bitcore's `WalletKey` objects +// OR string representing private keys to sign the transaction in WIF private key format separated by commas // // If multiple keys are given, each will be tested against the transaction's // scriptPubKeys. Only the valid private keys will be used to sign. @@ -756,6 +757,7 @@ fnToSign[Script.TX_SCRIPTHASH] = TransactionBuilder.prototype._signScriptHash; // // TransactionBuilder.prototype.sign = function(keys) { + if (typeof keys === "string") keys = keys.split(','); if (!(keys instanceof Array)) throw new Error('parameter should be an array'); diff --git a/test/test.TransactionBuilder.js b/test/test.TransactionBuilder.js index 0885e12..09701fc 100644 --- a/test/test.TransactionBuilder.js +++ b/test/test.TransactionBuilder.js @@ -935,7 +935,7 @@ describe('TransactionBuilder', function() { var b = getP2shBuilder(1); (function() { b.sign(testdata.dataUnspentSign.keyStringsP2sh[0]) - }).should.throw('array'); + }).should.not.throw('array'); });