All files / src/transaction makeSha256Condition.js

33.33% Statements 3/9
0% Branches 0/6
0% Functions 0/1
33.33% Lines 3/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 244x   4x   4x                                      
import { Buffer } from 'buffer'
 
import cc from 'five-bells-condition'
 
import ccJsonify from './utils/ccJsonify'
 
 
/**
 * @public
 * Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
 * @param {string} preimage Preimage to be hashed and wrapped in a crypto-condition
 * @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
 * @returns {object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
 */
export default function makeSha256Condition(preimage, json = true) {
    const sha256Fulfillment = new cc.PreimageSha256()
    sha256Fulfillment.preimage = new Buffer(preimage)
 
    if (json) {
        return ccJsonify(sha256Fulfillment)
    }
    return sha256Fulfillment
}