Last active
November 29, 2016 13:01
Prefix Condition
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
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 | |
} |
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
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