diff --git a/src/transaction/makeEd25519Condition.js b/src/transaction/makeEd25519Condition.js index 9bd1aee..1bc4e26 100644 --- a/src/transaction/makeEd25519Condition.js +++ b/src/transaction/makeEd25519Condition.js @@ -9,15 +9,18 @@ import ccJsonify from './utils/ccJsonify'; /** * Create an Ed25519 Cryptocondition from an Ed25519 public key to put into an Output of a Transaction * @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction + * @param {bool} json If true returns a json object otherwise a crypto-condition type * @returns {object} Ed25519 Condition (that will need to wrapped in an Output) */ -export default function makeEd25519Condition(publicKey, ccFormat=false) { +export default function makeEd25519Condition(publicKey, json=true) { const publicKeyBuffer = new Buffer(base58.decode(publicKey)); const ed25519Fulfillment = new cc.Ed25519(); ed25519Fulfillment.setPublicKey(publicKeyBuffer); - if (ccFormat) return ed25519Fulfillment; + if (json) { + return ccJsonify(ed25519Fulfillment) + } - return ccJsonify(ed25519Fulfillment) + return ed25519Fulfillment; } diff --git a/src/transaction/makeSha256Condition.js b/src/transaction/makeSha256Condition.js index 611ab01..234cd3e 100644 --- a/src/transaction/makeSha256Condition.js +++ b/src/transaction/makeSha256Condition.js @@ -5,15 +5,17 @@ import cc from 'five-bells-condition'; import ccJsonify from './utils/ccJsonify'; /** - * Create an Ed25519 Cryptocondition from an Ed25519 public key to put into an Output of a Transaction - * @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction - * @returns {object} Ed25519 Condition (that will need to wrapped in an Output) + * 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 {bool} json 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(secret, ccFormat=false) { +export default function makeSha256Condition(preimage, json=true) { const sha256Fulfillment = new cc.PreimageSha256(); - sha256Fulfillment.preimage = new Buffer(secret); + sha256Fulfillment.preimage = new Buffer(preimage); - if (ccFormat) return sha256Fulfillment; - - return ccJsonify(sha256Fulfillment) + if (json) { + return ccJsonify(sha256Fulfillment) + } + return sha256Fulfillment; } diff --git a/src/transaction/makeThresholdCondition.js b/src/transaction/makeThresholdCondition.js index f683f8e..dafcd03 100644 --- a/src/transaction/makeThresholdCondition.js +++ b/src/transaction/makeThresholdCondition.js @@ -5,12 +5,24 @@ import cc from 'five-bells-condition'; import ccJsonify from './utils/ccJsonify'; /** - * Create an Ed25519 Cryptocondition from an Ed25519 public key to put into an Output of a Transaction - * @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction - * @returns {object} Ed25519 Condition (that will need to wrapped in an Output) + * Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction + * @param {number} threshold + * @param {array} subconditions + * @param {bool} json If true returns a json object otherwise a crypto-condition type + * @returns {object} Sha256 Threshold Condition (that will need to wrapped in an Output) */ -export default function makeThresholdCondition(thresholdCondition, ccFormat=false) { - if (ccFormat) return new cc.ThresholdSha256(); +export default function makeThresholdCondition(threshold, subconditions=[], json=true) { + const thresholdCondition = new cc.ThresholdSha256(); + thresholdCondition.threshold = threshold; - return ccJsonify(thresholdCondition) + subconditions.forEach((subcondition) => { + // TODO: add support for Condition and URIs + thresholdCondition.addSubfulfillment(subcondition); + }); + + if (json) { + return ccJsonify(thresholdCondition) + } + + return thresholdCondition }