1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-24 19:10:12 +01:00

Add support for single and array of private keys

Pop out the first element (if an array) in the `rest attributes` and use that as the privateKeys array. Also use first private key if there are not enough supplied.
This commit is contained in:
Robert David 2018-08-15 14:16:06 +02:00 committed by GitHub
parent 80bf01eb55
commit 5b2ddf3958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -231,12 +231,13 @@ export default class Transaction {
* @returns {Object} The signed version of `transaction`. * @returns {Object} The signed version of `transaction`.
*/ */
static signTransaction(transaction, ...privateKeys) { static signTransaction(transaction, ...privateKeys) {
privateKeys = Array.isArray(privatekeys[0]) ? privateKeys[0]: privateKeys;
const signedTx = clone(transaction) const signedTx = clone(transaction)
const serializedTransaction = const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(transaction) Transaction.serializeTransactionIntoCanonicalString(transaction)
signedTx.inputs.forEach((input, index) => { signedTx.inputs.forEach((input, index) => {
const privateKey = privateKeys[index] const privateKey = privateKeys[index] || privateKeys[0]
const privateKeyBuffer = Buffer.from(base58.decode(privateKey)) const privateKeyBuffer = Buffer.from(base58.decode(privateKey))
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction const transactionUniqueFulfillment = input.fulfills ? serializedTransaction