1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 01:36:56 +01:00

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 * 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 {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) * @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 publicKeyBuffer = new Buffer(base58.decode(publicKey));
const ed25519Fulfillment = new cc.Ed25519(); const ed25519Fulfillment = new cc.Ed25519();
ed25519Fulfillment.setPublicKey(publicKeyBuffer); 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'; import ccJsonify from './utils/ccJsonify';
/** /**
* Create an Ed25519 Cryptocondition from an Ed25519 public key to put into an Output of a Transaction * Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
* @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction * @param {string} preimage Preimage to be hashed and wrapped in a crypto-condition
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output) * @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(); const sha256Fulfillment = new cc.PreimageSha256();
sha256Fulfillment.preimage = new Buffer(secret); sha256Fulfillment.preimage = new Buffer(preimage);
if (ccFormat) return sha256Fulfillment; if (json) {
return ccJsonify(sha256Fulfillment)
return ccJsonify(sha256Fulfillment) }
return sha256Fulfillment;
} }

View File

@ -5,12 +5,24 @@ import cc from 'five-bells-condition';
import ccJsonify from './utils/ccJsonify'; import ccJsonify from './utils/ccJsonify';
/** /**
* Create an Ed25519 Cryptocondition from an Ed25519 public key to put into an Output of a Transaction * Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
* @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction * @param {number} threshold
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output) * @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) { export default function makeThresholdCondition(threshold, subconditions=[], json=true) {
if (ccFormat) return new cc.ThresholdSha256(); 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
} }