-
Notifications
You must be signed in to change notification settings - Fork 17
Crypto condition example fail #12
Comments
Could you say which examples? And if possible provide a stack trace. |
I'm trying to execute this example
|
@diminator do you have time to look into this? |
it's a problem with the old version of BDB-driver - compatible with BDB 0.5 ot 0.6 I think. @manolodewiner can you take note? |
thanks |
Here are some untested bits and pieces of code // at the output of the transaction to-be-spent
let threshold = 2
let thresholdCondition = driver.Transaction.makeThresholdCondition(threshold, undefined, false )
let condition1 = driver.Transaction.makeEd25519Condition(user1.publicKey, false)
thresholdCondition.addSubconditionUri(condition1.getConditionUri())
let condition2 = driver.Transaction.makeEd25519Condition(user2.publicKey, false)
thresholdCondition.addSubconditionUri(condition2.getConditionUri())
let condition3 = driver.Transaction.makeEd25519Condition(user3.publicKey, false)
thresholdCondition.addSubconditionUri(condition3.getConditionUri())
let output = driver.Transaction.makeOutput(thresholdCondition);
output.public_keys = [user1.publicKey, user2.publicKey, user3.publicKey];
let transaction = driver.Transaction.makeCreateTransaction(
{ data: 'payload'},
{ metadata: 'test'},
[output],
creator.publicKey
); // at the input of the spending transaction
let fulfillment1 = driver.Transaction.makeEd25519Condition(user1.publicKey, false)
let fulfillment2 = driver.Transaction.makeEd25519Condition(user2.publicKey, false)
let fulfillment3 = driver.Transaction.makeEd25519Condition(user3.publicKey, false)
fulfillment1.sign(
new Buffer(driver.Transaction.serializeTransactionIntoCanonicalString(transferTransaction)),
new Buffer(base58.decode(user1.privateKey))
);
fulfillment3.sign(
new Buffer(driver.Transaction.serializeTransactionIntoCanonicalString(transferTransaction)),
new Buffer(base58.decode(user3.privateKey))
);
let fulfillment = driver.Transaction.makeThresholdCondition(1, undefined, false )
fulfillment.addSubfulfillment(fulfillment1);
fulfillment.addSubfulfillment(fulfillment2);
fulfillment.addSubfulfillment(fulfillment3);
let transferTransaction = driver.Transaction.makeTransferTransaction(
inputTransaction,
metadata,
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(receiver.publicKey))],
0
);
transferTransaction.inputs[0].fulfillment = fulfillment.serializeUri(); @manolodewiner can probably make this a bit more refined ;-) |
Here is an example based on the above code: const Buffer = require('buffer').Buffer
const BigchainDB = require('bigchaindb-driver')
const base58 = require('bs58')
const cryptoconditions = require('crypto-conditions')
const user1 = new BigchainDB.Ed25519Keypair()
const user2 = new BigchainDB.Ed25519Keypair()
const user3 = new BigchainDB.Ed25519Keypair()
const creator = new BigchainDB.Ed25519Keypair()
const receiver = new BigchainDB.Ed25519Keypair()
const API_PATH = 'https://test.ipdb.io/api/v1/'
const conn = new BigchainDB.Connection(API_PATH, {
app_id: 'xxxxxxxx',
app_key: 'xxxxxxxxxxxxxxxxxxx'
})
console.log(BigchainDB.Transaction.makeEd25519Condition(user1.publicKey))
// at the output of the transaction to-be-spent
// Generate threshold condition 2 out of 3
const threshold = 2
const condition1 = BigchainDB.Transaction.makeEd25519Condition(user1.publicKey, false)
const condition2 = BigchainDB.Transaction.makeEd25519Condition(user2.publicKey, false)
const condition3 = BigchainDB.Transaction.makeEd25519Condition(user3.publicKey, false)
const thresholdCondition = BigchainDB.Transaction.makeThresholdCondition(threshold, [condition1, condition2, condition3])
console.log(thresholdCondition)
let output = BigchainDB.Transaction.makeOutput(thresholdCondition);
output.public_keys = [user1.publicKey, user2.publicKey, user3.publicKey];
const tx = BigchainDB.Transaction.makeCreateTransaction({
data: 'payload'
}, {
metadata: 'test'
}, [output],
creator.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(tx, creator.privateKey)
// Send the transaction off to BigchainDB
const btn = document.getElementById('btn-transfer')
const txtTransfer = document.getElementById('txt-transfer')
conn.postTransaction(txSigned)
.then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
.then(res => {
console.log('Create Transaction', txSigned.id, 'accepted')
const elem = document.getElementById('lastTransaction')
elem.href = API_PATH + 'transactions/' + txSigned.id
elem.innerText = txSigned.id
btn.disabled = false
})
btn.onclick = function() {
txtTransfer.style.visibility = "visible"
let createTranfer = BigchainDB.Transaction.makeTransferTransaction(
[{ tx: txSigned,
output_index: 0
}],
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(receiver.publicKey))],
{
what: "Transfer transaction"
}
);
// at the input of the spending transaction
let fulfillment1 = BigchainDB.Transaction.makeEd25519Condition(user1.publicKey, false)
let fulfillment2 = BigchainDB.Transaction.makeEd25519Condition(user2.publicKey, false)
fulfillment1.sign(
new Buffer(BigchainDB.Transaction.serializeTransactionIntoCanonicalString(createTranfer)),
new Buffer(base58.decode(user1.privateKey))
);
fulfillment2.sign(
new Buffer(BigchainDB.Transaction.serializeTransactionIntoCanonicalString(createTranfer)),
new Buffer(base58.decode(user2.privateKey))
);
// 2 out of 3 need to sign the fulfillment. Still condition3 is needed as the "circuit definition" is needed.
// See https://github.com/bigchaindb/cryptoconditions/issues/94
let fulfillment = new cryptoconditions.ThresholdSha256()
fulfillment.threshold = 2
fulfillment.addSubfulfillment(fulfillment1.serializeUri())
fulfillment.addSubfulfillment(fulfillment2.serializeUri())
fulfillment.addSubconditionUri(condition3.getConditionUri())
//Sign the transaction
const fulfillmentUri = fulfillment.serializeUri()
createTranfer.inputs[0].fulfillment = fulfillmentUri
conn.postTransaction(createTranfer)
.then(() => conn.pollStatusAndFetchTransaction(createTranfer.id))
.then(res => {
const transfTransaction = document.getElementById('transfTransaction')
transfTransaction.href = API_PATH + 'transactions/' + createTranfer.id
transfTransaction.innerText = createTranfer.id
console.log('Transfer Transaction', createTranfer.id, 'accepted')
})
} Fyi: There is also a pull request created to simplify the creation of the fulfillment for the inputs: js-bigchaindb-driver/pull/119 |
Thank you for the example i'll try to translate this to python driver, my need is : |
I have just updated my previous comment with a code example, now using a threshold condition '2 out of 3' |
Thank you this make it clear for me Or in my previous message the idea is to use condition and threshold not only to have the signed quorum number but also to add other conditions on the transfer itself I really appreciate your reactive feedback |
Crytpconditions are useful to "describe a signed message such that multiple actors in a distributed system can all verify the same signed message and agree on whether it matches the description". |
Hi @manolodewiner , while executing the following code : I'm getting an error: Please suggest!! |
Hi @imdineshgrewal do not really know your problem, please try this code with node. If it does not work check that you have the BigchainDB 1.3 version and the latest version of the BigchainDB driver as well const Buffer = require('buffer').Buffer
const BigchainDB = require('bigchaindb-driver')
const base58 = require('bs58')
const cryptoconditions = require('crypto-conditions')
const user1 = new BigchainDB.Ed25519Keypair()
const user2 = new BigchainDB.Ed25519Keypair()
const user3 = new BigchainDB.Ed25519Keypair()
const creator = new BigchainDB.Ed25519Keypair()
const receiver = new BigchainDB.Ed25519Keypair()
const API_PATH = 'http://localhost:9984/api/v1/'
const conn = new BigchainDB.Connection(API_PATH, {
app_id: '',
app_key: ''
})
console.log(BigchainDB.Transaction.makeEd25519Condition(user1.publicKey))
// at the output of the transaction to-be-spent
// Generate threshold condition 2 out of 3
const threshold = 2
const condition1 = BigchainDB.Transaction.makeEd25519Condition(user1.publicKey, false)
const condition2 = BigchainDB.Transaction.makeEd25519Condition(user2.publicKey, false)
const condition3 = BigchainDB.Transaction.makeEd25519Condition(user3.publicKey, false)
const thresholdCondition = BigchainDB.Transaction.makeThresholdCondition(threshold, [condition1, condition2, condition3])
console.log(thresholdCondition)
let output = BigchainDB.Transaction.makeOutput(thresholdCondition);
output.public_keys = [user1.publicKey, user2.publicKey, user3.publicKey];
const tx = BigchainDB.Transaction.makeCreateTransaction({
data: 'payload'
}, {
metadata: 'test'
}, [output],
creator.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(tx, creator.privateKey)
// Send the transaction off to BigchainDB
conn.postTransaction(txSigned)
.then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
.then(res => {
console.log('Create Transaction', txSigned.id, 'accepted')
const elem = document.getElementById('lastTransaction')
elem.href = API_PATH + 'transactions/' + txSigned.id
elem.innerText = txSigned.id
transfer()
})
function transfer() {
let createTranfer = BigchainDB.Transaction.makeTransferTransaction(
[{ tx: txSigned,
output_index: 0
}],
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(receiver.publicKey))],
{
what: "Transfer transaction"
}
);
// at the input of the spending transaction
let fulfillment1 = BigchainDB.Transaction.makeEd25519Condition(user1.publicKey, false)
let fulfillment2 = BigchainDB.Transaction.makeEd25519Condition(user2.publicKey, false)
fulfillment1.sign(
new Buffer(BigchainDB.Transaction.serializeTransactionIntoCanonicalString(createTranfer)),
new Buffer(base58.decode(user1.privateKey))
);
fulfillment2.sign(
new Buffer(BigchainDB.Transaction.serializeTransactionIntoCanonicalString(createTranfer)),
new Buffer(base58.decode(user2.privateKey))
);
// 2 out of 3 need to sign the fulfillment. Still condition3 is needed as the "circuit definition" is needed.
// See https://github.com/bigchaindb/cryptoconditions/issues/94
let fulfillment = new cryptoconditions.ThresholdSha256()
fulfillment.threshold = 2
fulfillment.addSubfulfillment(fulfillment1.serializeUri())
fulfillment.addSubfulfillment(fulfillment2.serializeUri())
fulfillment.addSubconditionUri(condition3.getConditionUri())
//Sign the transaction
const fulfillmentUri = fulfillment.serializeUri()
createTranfer.inputs[0].fulfillment = fulfillmentUri
conn.postTransaction(createTranfer)
.then(() => conn.pollStatusAndFetchTransaction(createTranfer.id))
.then(res => {
const transfTransaction = document.getElementById('transfTransaction')
transfTransaction.href = API_PATH + 'transactions/' + createTranfer.id
transfTransaction.innerText = createTranfer.id
console.log('Transfer Transaction', createTranfer.id, 'accepted')
})
} |
Btw, this code is now living here along with other examples: |
@manolodewiner |
Hi @manolodewiner, How to use the following in the javascript(browser): |
Hi @imdineshgrewal I would like to help you, but I don't understand what you mean by how to use it. Please use our Gitter to ask questions, this is an issue in the Kyber repo. |
Hi @manolodewiner , i want to use the following node.js modules in the javascript |
Okay, can you please use Gitter. |
@manolodewiner Sure, Thanks |
This repository (bigchaindb/kyber) contains examples that worked with older versions of BigchainDB, but the stuff in this repository hasn't been maintained and the examples almost certainly won't work with newer versions of BigchainDB. Therefore we are closing all the old issues, marking the repo as old/not-supported, and archiving the repo. You can find newer examples in other places. |
Crypto condition examples failed due to driver and missing lib from python
Seems the bigchaindb evolved while example didn't
Any update on this?
The text was updated successfully, but these errors were encountered: