All files / src/transaction makeEd25519Condition.js

90.91% Statements 10/11
50% Branches 3/6
100% Functions 1/1
90.91% Lines 10/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 284x   4x 4x   4x                   8x 8x   8x 8x   8x 8x          
import { Buffer } from 'buffer'
 
import base58 from 'bs58'
import cc from 'five-bells-condition'
 
import ccJsonify from './utils/ccJsonify'
 
 
/**
 * @public
 * 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 {boolean} [json=true] 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, json = true) {
    const publicKeyBuffer = new Buffer(base58.decode(publicKey))
 
    const ed25519Fulfillment = new cc.Ed25519()
    ed25519Fulfillment.setPublicKey(publicKeyBuffer)
 
    Eif (json) {
        return ccJsonify(ed25519Fulfillment)
    }
 
    return ed25519Fulfillment
}