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 | Date | |
---|---|---|---|
|
a9fb073072 | ||
|
b79c8f5cd8 | ||
|
75e8dac075 | ||
|
f8a924d214 | ||
|
197ece2264 | ||
|
a49e935b8f | ||
|
692cbe56d0 | ||
|
0462aca426 | ||
|
19db948726 | ||
|
1a61cde58d | ||
|
769cb59c34 | ||
|
3ef181b6b9 | ||
|
91caf13f1e | ||
|
98410ca69c | ||
|
0a400550a3 | ||
|
490c1e1017 | ||
|
368c04279e | ||
|
fe08f26a43 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -17,3 +17,4 @@ package-lock.json
|
|||
coverage
|
||||
coverage.lcov
|
||||
.nyc_output
|
||||
yarn.lock
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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 }
|
||||
)]
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user