1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-29 08:07:51 +01:00

update JS driver to sign single message

This commit is contained in:
diminator 2017-04-24 14:44:54 +02:00
parent c4a2452aa7
commit 4cec46e10b

View File

@ -4,21 +4,7 @@ import clone from 'clone';
export default function serializeTransactionIntoCanonicalString(transaction, input) {
// BigchainDB signs fulfillments by serializing transactions into a "canonical" format where
// each fulfillment URI is removed before sorting the remaining keys
const tx = clone(transaction);
let match;
tx.inputs.forEach((_input) => {
if (!(_input && input && _input['fulfills'] && input['fulfills']
&& !(_input['fulfills']['txid'] === input['fulfills']['txid']
&& _input['fulfills']['output'] === input['fulfills']['output']))) {
match = tx.inputs.indexOf(_input);
}
_input.fulfillment = null;
});
if (input && match >= 0 && tx.inputs) {
tx.inputs = [tx.inputs[match]];
}
// Sort the keys
return stableStringify(tx, (a, b) => (a.key > b.key ? 1 : -1));
}