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:
parent
80bf01eb55
commit
5b2ddf3958
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user