1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2025-01-01 01:27:54 +01:00

cc2 threshold condition creation

This commit is contained in:
Scott Sadler 2017-06-20 11:35:25 +02:00
parent 07e6584cf4
commit 35944d6d75
2 changed files with 25 additions and 14 deletions

View File

@ -33,13 +33,10 @@ export default function ccJsonify(fulfillment) {
if (fulfillment.getTypeId() === 2) { if (fulfillment.getTypeId() === 2) {
return { return {
'details': { 'details': {
'type_id': 2, 'type': 'threshold-sha-256',
'type': 'fulfillment',
'bitmask': fulfillment.getBitmask(),
'threshold': fulfillment.threshold, 'threshold': fulfillment.threshold,
'subfulfillments': fulfillment.subconditions.map((subcondition) => { 'subfulfillments': fulfillment.subconditions.map((subcondition) => {
const subconditionJson = ccJsonify(subcondition.body) const subconditionJson = ccJsonify(subcondition.body)
subconditionJson.details.weight = 1
return subconditionJson.details return subconditionJson.details
}) })
}, },
@ -48,13 +45,11 @@ export default function ccJsonify(fulfillment) {
} }
if (fulfillment.getTypeId() === 4) { if (fulfillment.getTypeId() === 4) {
jsonBody.details.type_id = 4 jsonBody.details.type = 'ed25519-sha-256'
jsonBody.details.bitmask = 32
if ('publicKey' in fulfillment) { if ('publicKey' in fulfillment) {
jsonBody.details.signature = null jsonBody.details.signature = null
jsonBody.details.public_key = base58.encode(fulfillment.publicKey) jsonBody.details.public_key = base58.encode(fulfillment.publicKey)
jsonBody.details.type = 'fulfillment'
} }
} }

View File

@ -28,18 +28,34 @@ test('Valid CREATE transaction is evaluated by BigchainDB', t => {
.then(resTx => t.truthy(resTx)) .then(resTx => t.truthy(resTx))
}) })
test('Ed25519 condition correctly formed', t => { test('Ed25519 condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS' const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const output = Transaction.makeOutput(Transaction.makeEd25519Condition(publicKey))
const target = { const target = {
details: { details: {
type_id: 4, type: 'ed25519-sha-256',
bitmask: 32,
signature: null,
public_key: publicKey, public_key: publicKey,
type: 'fulfillment' signature: null,
}, },
uri: 'ni:///sha-256;uLdVX7FEjLWVDkAkfMAkEqPPwFqZj7qfiGE152t_x5c?fpt=ed25519-sha-256&cost=131072' uri: 'ni:///sha-256;uLdVX7FEjLWVDkAkfMAkEqPPwFqZj7qfiGE152t_x5c?fpt=ed25519-sha-256&cost=131072'
} }
t.deepEqual(target, output.condition) t.deepEqual(target, Transaction.makeEd25519Condition(publicKey))
})
test('Threshold condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const condition = Transaction.makeThresholdCondition(
1, [Transaction.makeEd25519Condition(publicKey, false)])
const target = {
details: {
type: 'threshold-sha-256',
threshold: 1,
subfulfillments: [{
type: 'ed25519-sha-256',
public_key: publicKey,
signature: null,
}]
},
uri: 'ni:///sha-256;VBIfZSoBprUQy-LVNAzaZ2q-eyWbrcPKtBg1PuNXIpQ?fpt=threshold-sha-256&cost=132096&subtypes=ed25519-sha-256'
}
t.deepEqual(target, condition)
}) })