mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-12-29 08:07:51 +01:00
Merge pull request #61 from bigchaindb/threshold-public-keys
Encode public_keys array for threshold conditions
This commit is contained in:
commit
f63a868bc9
@ -10,10 +10,20 @@ export default function makeOutput(condition, amount = '1') {
|
||||
if (typeof amount !== 'string') {
|
||||
throw new TypeError('`amount` must be of type string')
|
||||
}
|
||||
const publicKeys = []
|
||||
const getPublicKeys = details => {
|
||||
if (details.type === 'ed25519-sha-256') {
|
||||
if (!publicKeys.includes(details.public_key)) {
|
||||
publicKeys.push(details.public_key)
|
||||
}
|
||||
} else if (details.type === 'threshold-sha-256') {
|
||||
details.subfulfillments.map(getPublicKeys)
|
||||
}
|
||||
}
|
||||
getPublicKeys(condition.details)
|
||||
return {
|
||||
'amount': amount,
|
||||
condition,
|
||||
'public_keys': condition.details.hasOwnProperty('public_key') ?
|
||||
[condition.details.public_key] : [],
|
||||
'amount': amount,
|
||||
'public_keys': publicKeys,
|
||||
}
|
||||
}
|
||||
|
@ -19,21 +19,34 @@ test('Ed25519 condition encoding', t => {
|
||||
|
||||
test('Threshold condition encoding', t => {
|
||||
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
||||
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
|
||||
const condition = Transaction.makeThresholdCondition(
|
||||
1, [Transaction.makeEd25519Condition(publicKey, false)])
|
||||
1, [ed25519, ed25519])
|
||||
const output = Transaction.makeOutput(condition)
|
||||
const target = {
|
||||
details: {
|
||||
type: 'threshold-sha-256',
|
||||
threshold: 1,
|
||||
subfulfillments: [{
|
||||
type: 'ed25519-sha-256',
|
||||
public_key: publicKey,
|
||||
signature: null,
|
||||
}]
|
||||
condition: {
|
||||
details: {
|
||||
type: 'threshold-sha-256',
|
||||
threshold: 1,
|
||||
subfulfillments: [
|
||||
{
|
||||
type: 'ed25519-sha-256',
|
||||
public_key: publicKey,
|
||||
signature: null,
|
||||
},
|
||||
{
|
||||
type: 'ed25519-sha-256',
|
||||
public_key: publicKey,
|
||||
signature: null,
|
||||
}
|
||||
]
|
||||
},
|
||||
uri: 'ni:///sha-256;xTeBhQj7ae5Tym7cp83fwtkesQnhdwNwDEMIYwnf2g0?fpt=threshold-sha-256&cost=133120&subtypes=ed25519-sha-256',
|
||||
},
|
||||
uri: 'ni:///sha-256;VBIfZSoBprUQy-LVNAzaZ2q-eyWbrcPKtBg1PuNXIpQ?fpt=threshold-sha-256&cost=132096&subtypes=ed25519-sha-256'
|
||||
amount: '1',
|
||||
public_keys: [publicKey]
|
||||
}
|
||||
t.deepEqual(target, condition)
|
||||
t.deepEqual(target, output)
|
||||
})
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
test('Create valid output with default amount', t => {
|
||||
const condition = {
|
||||
details: {
|
||||
type: 'ed25519-sha-256',
|
||||
public_key: 'abc'
|
||||
}
|
||||
}
|
||||
@ -33,6 +34,7 @@ test('Create valid output with default amount', t => {
|
||||
test('Create valid output with custom amount', t => {
|
||||
const condition = {
|
||||
details: {
|
||||
type: 'ed25519-sha-256',
|
||||
public_key: 'abc'
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user