mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-02-14 21:10:32 +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') {
|
if (typeof amount !== 'string') {
|
||||||
throw new TypeError('`amount` must be of type 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 {
|
return {
|
||||||
'amount': amount,
|
|
||||||
condition,
|
condition,
|
||||||
'public_keys': condition.details.hasOwnProperty('public_key') ?
|
'amount': amount,
|
||||||
[condition.details.public_key] : [],
|
'public_keys': publicKeys,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,21 +19,34 @@ test('Ed25519 condition encoding', t => {
|
|||||||
|
|
||||||
test('Threshold condition encoding', t => {
|
test('Threshold condition encoding', t => {
|
||||||
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
||||||
|
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
|
||||||
const condition = Transaction.makeThresholdCondition(
|
const condition = Transaction.makeThresholdCondition(
|
||||||
1, [Transaction.makeEd25519Condition(publicKey, false)])
|
1, [ed25519, ed25519])
|
||||||
|
const output = Transaction.makeOutput(condition)
|
||||||
const target = {
|
const target = {
|
||||||
|
condition: {
|
||||||
details: {
|
details: {
|
||||||
type: 'threshold-sha-256',
|
type: 'threshold-sha-256',
|
||||||
threshold: 1,
|
threshold: 1,
|
||||||
subfulfillments: [{
|
subfulfillments: [
|
||||||
|
{
|
||||||
type: 'ed25519-sha-256',
|
type: 'ed25519-sha-256',
|
||||||
public_key: publicKey,
|
public_key: publicKey,
|
||||||
signature: null,
|
signature: null,
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
uri: 'ni:///sha-256;VBIfZSoBprUQy-LVNAzaZ2q-eyWbrcPKtBg1PuNXIpQ?fpt=threshold-sha-256&cost=132096&subtypes=ed25519-sha-256'
|
{
|
||||||
|
type: 'ed25519-sha-256',
|
||||||
|
public_key: publicKey,
|
||||||
|
signature: null,
|
||||||
}
|
}
|
||||||
t.deepEqual(target, condition)
|
]
|
||||||
|
},
|
||||||
|
uri: 'ni:///sha-256;xTeBhQj7ae5Tym7cp83fwtkesQnhdwNwDEMIYwnf2g0?fpt=threshold-sha-256&cost=133120&subtypes=ed25519-sha-256',
|
||||||
|
},
|
||||||
|
amount: '1',
|
||||||
|
public_keys: [publicKey]
|
||||||
|
}
|
||||||
|
t.deepEqual(target, output)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
test('Create valid output with default amount', t => {
|
test('Create valid output with default amount', t => {
|
||||||
const condition = {
|
const condition = {
|
||||||
details: {
|
details: {
|
||||||
|
type: 'ed25519-sha-256',
|
||||||
public_key: 'abc'
|
public_key: 'abc'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,6 +34,7 @@ test('Create valid output with default amount', t => {
|
|||||||
test('Create valid output with custom amount', t => {
|
test('Create valid output with custom amount', t => {
|
||||||
const condition = {
|
const condition = {
|
||||||
details: {
|
details: {
|
||||||
|
type: 'ed25519-sha-256',
|
||||||
public_key: 'abc'
|
public_key: 'abc'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user