makeXXXCondition signature and docs

This commit is contained in:
diminator 2017-05-02 23:59:02 +02:00
parent 002fb40011
commit 8702e4c6f2
3 changed files with 34 additions and 17 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
}