mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-12-29 08:07:51 +01:00
cc2 threshold condition creation
This commit is contained in:
parent
07e6584cf4
commit
35944d6d75
@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
|
30
test/test.js
30
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)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user