Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing array of private keys, or single private key to "signTransaction()" method #237

Open
robertdavid010 opened this issue Aug 14, 2018 · 2 comments

Comments

@robertdavid010
Copy link

Currently the signTransaction() method uses rest parameters to get an array of private keys to be used for signing transaction inputs.

The method expects a corresponding private key for every transaction input at the same array index. However, since the rest parameter collects unassigned parameters into an array, it is not possible to dynamically/programatically set the number of private keys passed to the method.

https://github.com/bigchaindb/js-bigchaindb-driver/blob/master/src/transaction.js#L239

static signTransaction(transaction, ...privateKeys) {
    ...
    signedTx.inputs.forEach((input, index) => {
        const privateKey = privateKeys[index]
        ...
    }
}

Suggested improvement would be to support passing an array of private keys, as well as defaulting to using only the first private key, if only one is passed, to sign all inputs.

@future-is-present
Copy link
Contributor

@robertdavid010 thanks for creating the issue!
I am not sure if we should support passing an array of private keys. Technically is possible but I don't think that is a good practice to have several private keys (from different entities) and sign the transaction at once. The correct way would be that each entity that has a private key to sign his/her inputs and then sends it to the next entity.

@robertdavid010
Copy link
Author

This does not cover very well the case of spending multiple outputs/deposits of singular divisible assets from a single address. Regardless of use case, the inability to programmatically define the attributes corresponding to the tx inputs array means you have to write limited output transactions, and chain them? This enforcing of a pattern of use through limiting the method itself is extremely restrictive to even the basic use case of transfer of simple assets using multiple, but a non-derministic number of inputs.

At the very least to support the spending of inevitable "dust" caused by UTXO model, the method should support signing of all inputs with a single private key, since that is the most likely scenario in which you want to be able to support a non-deterministic number of inputs, and yet not support the pattern of sending multiple private keys to a single transaction.

Also its an easy but sloppy work around to currently support this (add 100+ attributes of the same private key to the method call)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants