1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-06-25 18:56:42 +02:00

Compare commits

...

18 Commits

Author SHA1 Message Date
vrde
a9fb073072
Release 0.3.0 2017-07-05 18:16:17 +02:00
vrde
b79c8f5cd8
Update README compatibility matrix 2017-07-05 18:14:15 +02:00
vrde
75e8dac075
Merge branch 'update-travis-to-bigchaindb-1.0' 2017-07-05 18:11:16 +02:00
vrde
f8a924d214
Update BigchainDB docker container for travis to 1.0.0 2017-07-05 18:06:13 +02:00
vrde
197ece2264
Merge branch 'greenkeeper/eslint-4.1.1' 2017-07-05 17:58:21 +02:00
vrde
a49e935b8f
Fix eslint errors 2017-07-05 17:52:07 +02:00
greenkeeper[bot]
692cbe56d0
chore(package): update eslint to version 4.1.1
Closes #64
2017-07-05 17:52:07 +02:00
vrde
0462aca426 Merge pull request #72 from bigchaindb/test-combine
Test combine PRs
2017-07-05 16:38:03 +02:00
Scott Sadler
19db948726 add has subcondition to ccJsonLoad test 2017-07-05 15:39:47 +02:00
Scott Sadler
1a61cde58d add additional test for ccJsonLoad 2017-07-05 15:09:33 +02:00
vrde
769cb59c34 Merge pull request #73 from bigchaindb/greenkeeper/yarn-0.27.5
Update yarn to the latest version 🚀
2017-07-05 11:39:47 +02:00
greenkeeper[bot]
3ef181b6b9 fix(package): update yarn to version 0.27.5 2017-07-04 06:26:54 +00:00
diminator
91caf13f1e
ignore yarn.lock 2017-06-30 21:52:47 +02:00
vrde
98410ca69c Merge pull request #70 from bigchaindb/greenkeeper/ava-0.20.0
Update ava to the latest version 🚀
2017-06-30 15:19:34 +02:00
Scott Sadler
0a400550a3 Merge branch 'output-index' into combine 2017-06-30 10:02:14 +02:00
Scott Sadler
490c1e1017 fulfills.output -> fulfills.output_index 2017-06-29 11:40:29 +02:00
Scott Sadler
368c04279e point travis at bigchaindb master 2017-06-28 10:10:46 +02:00
Scott Sadler
fe08f26a43 remove signature in details and rename subfulfillments to subconditions 2017-06-28 01:25:07 +02:00
12 changed files with 47 additions and 41 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ package-lock.json
coverage
coverage.lcov
.nyc_output
yarn.lock

View File

@ -18,7 +18,7 @@ before_install:
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
-e BIGCHAINDB_DATABASE_BACKEND=mongodb
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1
bigchaindb/bigchaindb:1.0.0rc1
bigchaindb/bigchaindb:1.0.0
start
- gem install cowsay
- npm install -g codecov

View File

@ -13,7 +13,7 @@
| BigchainDB Server | BigchainDB JavaScript Driver |
| ----------------- |------------------------------|
| `0.10` | `0.1.x` |
| `1.0` | `0.2.x` |
| `1.0` | `0.3.x` |
## Contents

View File

@ -1,6 +1,6 @@
{
"name": "bigchaindb-driver",
"version": "0.2.0",
"version": "0.3.0",
"description": "Node.js driver for BigchainDB",
"homepage": "https://www.bigchaindb.com/",
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",
@ -48,7 +48,7 @@
"babel-preset-latest": "^6.22.0",
"babel-runtime": "^6.22.0",
"cross-env": "^5.0.1",
"eslint": "^3.14.1",
"eslint": "^4.1.1",
"eslint-config-ascribe": "^3.0.4",
"eslint-plugin-import": "^2.2.0",
"husky": "^0.14.0",
@ -76,7 +76,7 @@
"query-string": "^4.3.4",
"sprintf-js": "^1.0.3",
"tweetnacl": "^1.0.0",
"yarn": "^0.24.5"
"yarn": "^0.27.5"
},
"keywords": [
"bigchaindb",

View File

@ -30,12 +30,8 @@ export default function request(url, config = {}, onlyJsonResponse = true) {
}
return baseRequest(apiUrl, requestConfig)
.then((res) => onlyJsonResponse ? res.json() : // eslint-disable-line no-confusing-arrow
{
json: res.json(),
url: res.url
})
.catch((err) => {
.then(res => (onlyJsonResponse ? res.json() : { json: res.json(), url: res.url }))
.catch(err => {
console.error(err)
throw err
})

View File

@ -10,11 +10,11 @@ import coreObjectEntries from 'core-js/library/fn/object/entries'
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
if (filter && Array.isArray(filter)) {
return applyFilterOnObject(obj, isInclusion ? ((_, key) => coreIncludes(filter, key))
: ((_, key) => !coreIncludes(filter, key)))
: ((_, key) => !coreIncludes(filter, key)))
} else if (filter && typeof filter === 'function') {
// Flip the filter fn's return if it's for inclusion
return applyFilterOnObject(obj, isInclusion ? filter
: (...args) => !filter(...args))
: (...args) => !filter(...args))
} else {
throw new Error('The given filter is not an array or function. Exclude aborted')
}

View File

@ -17,7 +17,7 @@ export default function makeOutput(condition, amount = '1') {
publicKeys.push(details.public_key)
}
} else if (details.type === 'threshold-sha-256') {
details.subfulfillments.map(getPublicKeys)
details.subconditions.map(getPublicKeys)
}
}
getPublicKeys(condition.details)

View File

@ -25,15 +25,15 @@ import makeTransaction from './makeTransaction'
// TODO:
// - Make `metadata` optional argument
export default function makeTransferTransaction(
unspentTransaction,
metadata,
outputs,
...outputIndices
) {
unspentTransaction,
metadata,
outputs,
...outputIndices
) {
const inputs = outputIndices.map((outputIndex) => {
const fulfilledOutput = unspentTransaction.outputs[outputIndex]
const transactionLink = {
'output': outputIndex,
'output_index': outputIndex,
'transaction_id': unspentTransaction.id,
}
@ -42,7 +42,7 @@ export default function makeTransferTransaction(
const assetLink = {
'id': unspentTransaction.operation === 'CREATE' ? unspentTransaction.id
: unspentTransaction.asset.id
: unspentTransaction.asset.id
}
return makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)

View File

@ -22,12 +22,12 @@ export default function ccJsonLoad(conditionJson) {
if (conditionJson.type === 'threshold-sha-256') {
fulfillment = new cc.ThresholdSha256()
fulfillment.threshold = conditionJson.threshold
conditionJson.subfulfillments.forEach((subfulfillmentJson) => {
const subfulfillment = ccJsonLoad(subfulfillmentJson)
if ('getConditionUri' in subfulfillment) {
fulfillment.addSubfulfillment(subfulfillment)
} else if ('serializeUri' in subfulfillment) {
fulfillment.addSubcondition(subfulfillment)
conditionJson.subconditions.forEach((subconditionJson) => {
const subcondition = ccJsonLoad(subconditionJson)
if ('getConditionUri' in subcondition) {
fulfillment.addSubfulfillment(subcondition)
} else if ('serializeUri' in subcondition) {
fulfillment.addSubcondition(subcondition)
}
})
}
@ -35,9 +35,6 @@ export default function ccJsonLoad(conditionJson) {
if (conditionJson.type === 'ed25519-sha-256') {
fulfillment = new cc.Ed25519Sha256()
fulfillment.publicKey = new Buffer(base58.decode(conditionJson.public_key))
if (conditionJson.signature) {
fulfillment.signature = new Buffer(base58.decode(conditionJson.signature))
}
}
return fulfillment
}

View File

@ -35,7 +35,7 @@ export default function ccJsonify(fulfillment) {
'details': {
'type': 'threshold-sha-256',
'threshold': fulfillment.threshold,
'subfulfillments': fulfillment.subconditions.map((subcondition) => {
'subconditions': fulfillment.subconditions.map((subcondition) => {
const subconditionJson = ccJsonify(subcondition.body)
return subconditionJson.details
})
@ -48,7 +48,6 @@ export default function ccJsonify(fulfillment) {
jsonBody.details.type = 'ed25519-sha-256'
if ('publicKey' in fulfillment) {
jsonBody.details.signature = null
jsonBody.details.public_key = base58.encode(fulfillment.publicKey)
}
}

View File

@ -9,7 +9,6 @@ test('Ed25519 condition encoding', t => {
details: {
type: 'ed25519-sha-256',
public_key: publicKey,
signature: null,
},
uri: 'ni:///sha-256;uLdVX7FEjLWVDkAkfMAkEqPPwFqZj7qfiGE152t_x5c?fpt=ed25519-sha-256&cost=131072'
}
@ -21,23 +20,21 @@ test('Threshold condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
const condition = Transaction.makeThresholdCondition(
1, [ed25519, ed25519])
1, [ed25519, ed25519])
const output = Transaction.makeOutput(condition)
const target = {
condition: {
details: {
type: 'threshold-sha-256',
threshold: 1,
subfulfillments: [
subconditions: [
{
type: 'ed25519-sha-256',
public_key: publicKey,
signature: null,
},
{
type: 'ed25519-sha-256',
public_key: publicKey,
signature: null,
}
]
},
@ -67,6 +64,22 @@ test('Fulfillment correctly formed', t => {
const msg = Transaction.serializeTransactionIntoCanonicalString(txTransfer)
const txSigned = Transaction.signTransaction(txTransfer, alice.privateKey)
t.truthy(cc.validateFulfillment(txSigned.inputs[0].fulfillment,
txCreate.outputs[0].condition.uri,
new Buffer(msg)))
txCreate.outputs[0].condition.uri,
new Buffer(msg)))
})
test('CryptoConditions JSON load', t => {
const cond = Transaction.ccJsonLoad({
type: 'threshold-sha-256',
threshold: 1,
subconditions: [{
type: 'ed25519-sha-256',
public_key: 'a'
},
{
hash: 'a'
}],
})
t.truthy(cond.subconditions.length === 2)
})

View File

@ -85,7 +85,7 @@ test('Create TRANSFER transaction based on CREATE transaction', t => {
[aliceOutput],
[makeInputTemplate(
[alice.publicKey],
{ output: 0, transaction_id: createTx.id }
{ output_index: 0, transaction_id: createTx.id }
)]
]
@ -113,7 +113,7 @@ test('Create TRANSFER transaction based on TRANSFER transaction', t => {
[aliceOutput],
[makeInputTemplate(
[alice.publicKey],
{ output: 0, transaction_id: transferTx.id }
{ output_index: 0, transaction_id: transferTx.id }
)]
]