1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-28 15:47:50 +01:00

Merge branch 'ready-to-roll'

This commit is contained in:
vrde 2017-06-16 15:11:33 +02:00
commit ce0bef1538
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
7 changed files with 61 additions and 114 deletions

View File

@ -1,5 +1,10 @@
{
"presets": ["es2015-no-commonjs"],
"presets": [
"@ava/stage-4",
"@ava/transform-test-files",
"es2015-no-commonjs"
],
"plugins": [
"transform-export-extensions",
"transform-object-assign",
@ -23,4 +28,4 @@
]
}
}
}
}

View File

@ -1,25 +0,0 @@
language: node_js
node_js: node
env:
- CXX=g++-4.9
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
install: npm install
script:
- npm test
- npm run build
cache:
directories:
- node_modules
notifications:
email: false

View File

@ -11,19 +11,14 @@
| BigchainDB Server | BigchainDB JavaScript Driver |
| ----------------- |------------------------------|
| `~=0.10.1` | `~=1.0.0` |
| `0.10` | `0.1.0` |
## Contents
* [Installation](#installation)
* [Usage](#usage)
* [Example: Create a transaction](#example-create-a-transaction)
* [More examples](#more-examples)
* [Documentation](#bigchaindb-documentation)
* [Speed Optimizations](#speed-optimizations)
* [Warnings](#warnings)
* [npm Releases](#npm-releases)
* [Authors](#authors)
* [License](#license)
@ -33,13 +28,6 @@
npm install bigchaindb-driver
```
## Usage
You'll probably need a babel here and a bundler there. Alternatively, use one of the bundled dist versions:
- `dist/bundle/`: Babelified and packaged with dependencies, so you can drop it in anywhere you want.
- `dist/node/`: Babelified into a CommonJS module, so you can drop it in on any node project.
### Example: Create a transaction
```js
@ -67,8 +55,8 @@ const tx = driver.Transaction.makeCreateTransaction(
alice.publicKey
)
// Optional: You've got everything you need, except for an asset
// and metadata. Maybe define them here, any JSON-serializable object
// Optional: You've got everything you need, except for an asset
// and metadata. Maybe define them here, any JSON-serializable object
// will do
// Ok, now that you have a transaction, you need to *sign* it
@ -85,12 +73,6 @@ conn.postTransaction(txSigned)
.then((res) => console.log('Transaction status:', res.status))
```
### More examples
You may also be interested in some [long-form tutorials with actual code](https://github.com/bigchaindb/kyber):
- [Kyber](https://github.com/bigchaindb/kyber): full suite of BigchainDB repos with tutorials, examples and experiments included.
## BigchainDB Documentation
- [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html)
@ -101,65 +83,11 @@ You may also be interested in some [long-form tutorials with actual code](https:
## Speed Optimizations
This implementation plays "safe" by using JS-native (or downgradable) libraries for its crypto-related functions to keep compatibilities with the browser. If you do want some more speed, feel free to explore the following:
This implementation plays "safe" by using JS-native (or downgradable) libraries for its crypto-related functions to keep compatibilities with the browser. If you do want some more speed, feel free to explore the following:
* [chloride](https://github.com/dominictarr/chloride), or its underlying [sodium](https://github.com/paixaop/node-sodium) library
* [node-sha3](https://github.com/phusion/node-sha3) -- **MAKE SURE** to use [steakknife's fork](https://github.com/steakknife/node-sha3) if [the FIPS 202 upgrade](https://github.com/phusion/node-sha3/pull/25) hasn't been merged (otherwise, you'll run into all kinds of hashing problems)
## Warnings
> Crypto-conditions
Make sure you keep using a crypto-conditions implementation that implements the older v1 draft (e.g.
[`five-bells-condition@v3.3.1`](https://github.com/interledgerjs/five-bells-condition/releases/tag/v3.3.1)).
BigchainDB Server 0.10 does not implement the newer version of the spec and **WILL** fail if you try using a newer implementation of crypto-conditions.
> SHA3
Make sure to use a SHA3 implementation that has been upgraded as per [FIPS 202](http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf). Otherwise, the hashes you generate **WILL** be invalid in the eyes of the BigchainDB Server.
> Ed25519
If you do end up replacing `tweetnacl` with `chloride` (or any other `Ed25519` package), you might want to double check that it gives you a correct public/private (or verifying/signing, if they use
that lingo) key pair.
An example BigchainDB Server-generated key pair (encoded in `base58`):
- Public: `DjPMHDD9JtgypDKY38mPz9f6owjAMAKhLuN1JfRAat8C`
- Private: `7Gf5YRch2hYTyeLxqNLgTY63D9K5QH2UQ7LYFeBGuKvo`
Your package should be able to take in the decoded version of the **private** key and return you the same **public** key (once you encode that to `base58`).
## npm Releases
For a new **patch release**, execute on the machine where you're logged into your npm account:
```bash
npm run release
```
Command is powered by [`release-it`](https://github.com/webpro/release-it) package, defined in the `package.json`.
That's what the command does without any user interaction:
1. create release commit by updating version in `package.json`
1. create tag for that release commit
1. push commit & tag
1. create a new release on GitHub, with change log auto-generated from commit messages
1. update local dependencies to latest version
1. build bundled dist versions
1. publish to npm as a new release
If you want to create a **minor** or **major release**, use these commands:
```bash
npm run release-minor
```
```bash
npm run release-major
```
## Authors

View File

@ -1,6 +1,6 @@
{
"name": "bigchaindb-driver",
"version": "1.0.2",
"version": "0.1.0",
"description": "Node.js driver for BigchainDB",
"homepage": "https://www.bigchaindb.com/",
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",
@ -11,9 +11,10 @@
"license": "Apache-2.0",
"author": "BigchainDB",
"main": "./dist/node/index.js",
"browser": "./dist/browser/bundle.min.js",
"scripts": {
"lint": "eslint ./",
"build": "npm run clean && npm run build:bundle && npm run build:cjs && npm run build:dist",
"build": "npm run clean && npm run build:cjs && npm run build:dist",
"build:bundle": "webpack",
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
"build:dist": "cross-env NODE_ENV=production webpack -p",
@ -22,7 +23,7 @@
"release": "./node_modules/release-it/bin/release.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-minor": "./node_modules/release-it/bin/release.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-major": "./node_modules/release-it/bin/release.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"prepublishOnly": "npm update && npm run build",
"prepublish": "npm update && npm run build",
"precommit": "npm run lint"
},
"devDependencies": {
@ -49,6 +50,7 @@
"webpack": "^2.2.1"
},
"dependencies": {
"browser-resolve": "^1.11.2",
"bs58": "^4.0.0",
"buffer": "^5.0.2",
"clone": "^2.1.0",
@ -71,5 +73,23 @@
"blockchain",
"decentralized",
"dapp"
]
],
"ava": {
"files": [
"test/*.js"
],
"source": [
"**/*.{js,jsx}",
"!node_modules/**/*",
"!dist/**/*"
],
"failFast": true,
"failWithoutAssertions": false,
"tap": true,
"powerAssert": false,
"require": [
"babel-register"
],
"babel": "inherit"
}
}

View File

@ -8,7 +8,7 @@
*/
export default function makeOutput(condition, amount = 1) {
return {
'amount': amount.toString(),
'amount': amount,
condition,
'public_keys': condition.details.hasOwnProperty('public_key') ?
[condition.details.public_key] : [],

View File

@ -1,11 +1,30 @@
import test from 'ava'
import { Ed25519Keypair, Transaction, Connection } from '../src'
test('foo', t => {
t.pass()
const API_PATH = 'http://localhost:9984/api/v1/'
test('Keypair is created', t => {
const keyPair = new Ed25519Keypair()
t.truthy(keyPair.publicKey)
t.truthy(keyPair.privateKey)
})
test('bar', async t => {
const bar = Promise.resolve('bar')
test('Valid CREATE transaction is evaluated by BigchainDB', t => {
const alice = new Ed25519Keypair()
const asset = { name: 'Shmui', type: 'cat' }
const metadata = { dayOfTheWeek: 'Caturday' }
t.is(await bar, 'bar')
const tx = Transaction.makeCreateTransaction(
asset,
metadata,
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
const conn = new Connection(API_PATH)
return conn.postTransaction(txSigned)
.then(resTx => t.truthy(resTx))
})

View File

@ -10,7 +10,7 @@ const PRODUCTION = process.env.NODE_ENV === 'production'
const PATHS = {
ENTRY: path.resolve(__dirname, './src/index.js'),
BUNDLE: path.resolve(__dirname, 'dist/bundle'),
BUNDLE: path.resolve(__dirname, 'dist/browser'),
NODE_MODULES: path.resolve(__dirname, 'node_modules'),
}