Last active
June 16, 2019 14:11
-
-
Save WietseWind/a3095ae0e844c1fdbb6cb6f143799912 to your computer and use it in GitHub Desktop.
Escrow Crypto Conditions based on UTF-8 buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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