1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-06-10 20:02:11 +02:00
js-bigchaindb-driver/src/transaction/serializeTransactionIntoCanonicalString.js
2017-05-03 01:02:50 +02:00

17 lines
604 B
JavaScript

import stableStringify from 'json-stable-stringify';
import clone from 'clone';
/**
* @public
* Canonically serializes a transaction into a string by sorting the keys
* @param {object} (transaction)
* @return {string} a canonically serialized Transaction
*/
export default function serializeTransactionIntoCanonicalString(transaction) {
// BigchainDB signs fulfillments by serializing transactions into a "canonical" format where
const tx = clone(transaction);
// TODO: set fulfillments to null
// Sort the keys
return stableStringify(tx, (a, b) => (a.key > b.key ? 1 : -1));
}