Skip to content

Instantly share code, notes, and snippets.

@WietseWind WietseWind/cc.js
Last active Jun 16, 2019

Embed
What would you like to do?
Escrow Crypto Conditions based on UTF-8 buffer
cc = require('five-bells-condition')
const fulfillment_bytes = Buffer.from('Hi! This is me testing :) 😇 🎉🎈🍺🎂🍾🍻...'.repeat(1), 'utf8') //.toString('hex').toUpperCase()
// Or random:
// const fulfillment_bytes = crypto.randomBytes(2)
console.log('EscrowFinish Fee:', 10 * (33 + Math.ceil(Buffer.byteLength(fulfillment_bytes) / 16)))
console.log()
// console.log(fulfillment_bytes)
const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(fulfillment_bytes)
var fulfillment = myFulfillment.serializeBinary().toString('hex').toUpperCase()
console.log('Fulfillment: ', fulfillment)
console.log(' ', myFulfillment.serializeUri())
var condition = myFulfillment.getConditionBinary().toString('hex').toUpperCase()
console.log('Condition : ', condition)
// 'A0258020' + sha256(fulfillment_bytes) + '810102'
console.log(' ', myFulfillment.getCondition().serializeUri())
console.log()
console.log(
'Fulfillment valid for Condition? ',
cc.validateFulfillment(
cc.Fulfillment.fromBinary(Buffer.from(fulfillment, 'hex')).serializeUri(),
cc.Condition.fromBinary(Buffer.from(condition, 'hex')).serializeUri()
)
)
console.log()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.