Skip to content

Instantly share code, notes, and snippets.

@elmurci
Last active November 29, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmurci/d3322fe3798335bac0aa6315349b4447 to your computer and use it in GitHub Desktop.
Save elmurci/d3322fe3798335bac0aa6315349b4447 to your computer and use it in GitHub Desktop.
Prefix Condition
function createWithSubcondition (pubKey, message) {
const sender_fulfillment = new cc.Ed25519()
// Set public_key
sender_fulfillment.setPublicKey(new Buffer(pubKey, 'hex'))
// Prefix
const prefix = new cc.PrefixSha256()
prefix.setPrefix(message)
prefix.setSubfulfillment(sender_fulfillment)
// Condition
const condition = prefix.getConditionUri()
console.log(colors.green.bold('SENDER') + '\n');
console.log(colors.grey.italic('By using a subcondition we embed the message as part of the condition.') + '\n')
console.log(colors.green('Condition: ' + condition) + '\n')
return condition
}
function fulfillWithSubcondition (pubKey, seed, message) {
const receiver_fulfillment = new cc.Ed25519()
console.log(colors.blue.bold('RECEIVER') + '\n');
console.log(colors.grey.italic('Receives the transaction and signs a message with his/her private key to fulfill the condition.') + '\n')
console.log(colors.grey.italic('The content of the message IS part of the condition.') + '\n')
receiver_fulfillment.setPublicKey(pubKey)
const condition = receiver_fulfillment.getConditionUri()
receiver_fulfillment.sign(message, seed)
const prefix = new cc.PrefixSha256()
prefix.setPrefix(message)
prefix.setSubfulfillment(receiver_fulfillment)
const fulfillment = prefix.serializeUri()
console.log(colors.blue('Fulfillment URI:' + fulfillment) + '\n')
return fulfillment
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment