diff --git a/src/transaction/utils/ccJsonify.js b/src/transaction/utils/ccJsonify.js index c80ec24..a33d0b6 100644 --- a/src/transaction/utils/ccJsonify.js +++ b/src/transaction/utils/ccJsonify.js @@ -33,13 +33,10 @@ export default function ccJsonify(fulfillment) { if (fulfillment.getTypeId() === 2) { return { 'details': { - 'type_id': 2, - 'type': 'fulfillment', - 'bitmask': fulfillment.getBitmask(), + 'type': 'threshold-sha-256', 'threshold': fulfillment.threshold, 'subfulfillments': fulfillment.subconditions.map((subcondition) => { const subconditionJson = ccJsonify(subcondition.body) - subconditionJson.details.weight = 1 return subconditionJson.details }) }, @@ -48,13 +45,11 @@ export default function ccJsonify(fulfillment) { } if (fulfillment.getTypeId() === 4) { - jsonBody.details.type_id = 4 - jsonBody.details.bitmask = 32 + jsonBody.details.type = 'ed25519-sha-256' if ('publicKey' in fulfillment) { jsonBody.details.signature = null jsonBody.details.public_key = base58.encode(fulfillment.publicKey) - jsonBody.details.type = 'fulfillment' } } diff --git a/test/test.js b/test/test.js index d6d6ccc..48b2fa6 100644 --- a/test/test.js +++ b/test/test.js @@ -28,18 +28,34 @@ test('Valid CREATE transaction is evaluated by BigchainDB', t => { .then(resTx => t.truthy(resTx)) }) -test('Ed25519 condition correctly formed', t => { +test('Ed25519 condition encoding', t => { const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS' - const output = Transaction.makeOutput(Transaction.makeEd25519Condition(publicKey)) const target = { details: { - type_id: 4, - bitmask: 32, - signature: null, + type: 'ed25519-sha-256', public_key: publicKey, - type: 'fulfillment' + signature: null, }, 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) })