All files / src/transaction serializeTransactionIntoCanonicalString.js

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 194x 4x                       37x     1090x    
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))
}