1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-06-15 17:13:18 +02:00

Compare commits

...

516 Commits

Author SHA1 Message Date
getlarge
17d3a02cb3
Release 4.3.0 2022-02-17 06:09:10 +01:00
getlarge
f9a4675726
Merge pull request #312 from bigchaindb/fet-improve-requests
feat: improve requests
2022-02-17 06:03:53 +01:00
getlarge
7a12ee7eb9
ci: extends wait delay 2022-02-16 08:17:44 +01:00
getlarge
eee8da4b78
fix: use abort-controller pkg for node <15 2022-02-16 08:17:30 +01:00
getlarge
2f3b2dbca1
ci: run BCDB node in background 2022-02-16 08:05:51 +01:00
getlarge
334a3f4d2d
Merge branch 'master' into fet-improve-requests 2022-02-16 07:59:56 +01:00
getlarge
1864f6fbb4
ci: update watched branch 2022-02-16 07:57:31 +01:00
getlarge
2ffbe99a2b
ci: create GH workflow 2022-02-16 07:56:28 +01:00
getlarge
ae13da59b4
ci: create GH action workflow 2022-02-16 07:38:57 +01:00
getlarge
30c15b962b
feat: export extra types 2022-02-15 14:13:13 +01:00
getlarge
1ba488b28f
fix: improve transaction typedefs 2022-02-15 14:13:04 +01:00
getlarge
fbc3d79d98
feat: update connection typedefs 2022-02-15 14:12:27 +01:00
getlarge
46599f5446
feat: add limit query for transaction search requests 2022-02-15 14:11:30 +01:00
getlarge
8c0c72622d
feat: ensure timeout and request are properly cleared 2022-02-15 14:10:49 +01:00
getlarge
c5fe1346b9
chore: update dependencies 2022-02-15 14:06:19 +01:00
getlarge
dc353ee5bc
chore: update lint rules 2022-02-15 08:07:38 +01:00
getlarge
38819a5934
fix: improve promises handling 2022-02-15 08:06:31 +01:00
getlarge
34289b0640
chore: update wepback config
declare Buffer as webpack plugin
2022-02-15 08:06:05 +01:00
getlarge
1f95bec2be
chore: update dev dependencies 2022-02-15 08:04:36 +01:00
getlarge
7c1e8be400
Release 4.2.2 2021-03-11 13:07:46 +01:00
getlarge
6aeece49cb
fix: improve typedefs
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-11 13:05:14 +01:00
getlarge
71a231a50a
fix: add delegateSignatureAsync method
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-11 13:04:17 +01:00
getlarge
76c877c649
Release 4.2.1 2021-03-10 16:34:41 +01:00
getlarge
f020a35ea2
fix: improve imports
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 16:31:43 +01:00
getlarge
9b395c14a6
fix: add missing types in package
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 16:15:20 +01:00
getlarge
d29b9c2566
Release 4.2.0 2021-03-10 15:48:37 +01:00
getlarge
6aa5f0100c
Merge pull request #308 from bigchaindb/add-type-defs
Add type defs
2021-03-10 15:38:17 +01:00
getlarge
1779f6eef4
fix: add type for TransactionOutput.condition
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 15:37:09 +01:00
getlarge
44dfc8f825
Merge branch 'add-type-defs' of github.com:bigchaindb/js-bigchaindb-driver into add-type-defs 2021-03-10 13:59:24 +01:00
getlarge
d5fd300cfc
fix: makeoutput input type
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 13:59:08 +01:00
getlarge
71fe66c1f5
fix: Crypto conditions parsers
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 13:59:07 +01:00
getlarge
af90b97460
fix: refine Crypoconditions parsers types
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 13:59:06 +01:00
getlarge
b177ca0de4
fix: refine types definitions
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 13:59:05 +01:00
getlarge
858acf2693
fix: add type definitions
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 13:59:04 +01:00
getlarge
d26f667feb
fix: module exports
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 13:59:02 +01:00
getlarge
c98cc8e499
fix: makeoutput input type 2021-03-10 13:58:38 +01:00
getlarge
2a104eb86b
fix: Crypto conditions parsers 2021-03-10 13:36:00 +01:00
getlarge
90a2cb2608
fix: refine Crypoconditions parsers types 2021-03-10 13:20:32 +01:00
getlarge
84bd4efe03
fix: refine types definitions 2021-03-10 11:03:53 +01:00
getlarge
5f6bef65c5
fix: add type definitions 2021-03-10 09:22:40 +01:00
getlarge
cd5c529324
fix: module exports 2021-03-10 09:22:37 +01:00
getlarge
7fe904061a
Merge pull request #307 from bigchaindb/update-dependencies
Update dependencies
2021-03-10 09:21:13 +01:00
getlarge
902885f7d1
Merge branches 'update-dependencies' and 'update-dependencies' of github.com:bigchaindb/js-bigchaindb-driver into update-dependencies 2021-03-10 09:10:26 +01:00
getlarge
abaa40b269
fix: run lint
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:10 +01:00
getlarge
611624fd7a
fix: lint config
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:09 +01:00
getlarge
3d49a6755e
fix: update example
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:07 +01:00
getlarge
978585d649
fix: update test constants
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:06 +01:00
getlarge
43c541d6d7
fix: minor transaction module improvements
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:05 +01:00
getlarge
272e6d6ae0
fix: update release-it config
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:03 +01:00
getlarge
736b2adc37
fix: update tests to latest AVA API
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:02 +01:00
getlarge
dc7634c9db
fix: update delegateSignTransaction callback
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:49:01 +01:00
getlarge
42112acd3e
fix: update travis config
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:59 +01:00
getlarge
656de69c64
fix: improve request errors
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:58 +01:00
getlarge
597ac56f1f
fix: update polyfills path
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:57 +01:00
getlarge
1b9bafa097
fix: regenerate doc
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:56 +01:00
getlarge
e3cca78886
fix: update webpack config
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:54 +01:00
getlarge
23c3fa50ef
fix: update babel and lint config
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:53 +01:00
getlarge
551180bceb
fix: update dependencies and test config
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 08:48:44 +01:00
getlarge
86d02c2f04
fix: run lint 2021-03-09 14:20:00 +01:00
getlarge
90466cf6ae
fix: lint config 2021-03-09 14:19:10 +01:00
getlarge
cc3aa3fdd3
fix: update example 2021-03-09 13:49:15 +01:00
getlarge
f5cd60e63d
fix: update test constants 2021-03-09 13:49:06 +01:00
getlarge
317bdd4d0f
fix: minor transaction module improvements 2021-03-09 12:32:29 +01:00
getlarge
41ce1178c7
fix: update release-it config 2021-03-09 12:20:24 +01:00
getlarge
ba87737d97
fix: update tests to latest AVA API 2021-03-09 10:57:37 +01:00
getlarge
d5894deec4
fix: update delegateSignTransaction callback 2021-03-09 09:50:33 +01:00
getlarge
3c76d3bb21
fix: update travis config 2021-03-09 08:16:09 +01:00
getlarge
1f27cd2300
fix: improve request errors 2021-03-09 07:52:03 +01:00
getlarge
57a3e89871
fix: update polyfills path 2021-03-09 07:51:36 +01:00
getlarge
e76c6227f8
fix: regenerate doc 2021-03-09 07:17:06 +01:00
getlarge
ad7763f76c
fix: update webpack config 2021-03-09 07:16:51 +01:00
getlarge
b3909b0f04
fix: update babel and lint config 2021-03-09 07:15:59 +01:00
getlarge
f0df142efb
fix: update dependencies and test config 2021-03-09 07:14:38 +01:00
getlarge
6dbafa8fad
Merge pull request #304 from bigchaindb/delegated-signature
Delegated signature
2020-12-21 07:35:18 +01:00
getlarge
344702200d fix: remove transaction from delegated signature callback
Signed-off-by: getlarge <ed@getlarge.eu>
2020-12-17 18:06:02 +01:00
getlarge
a4d8ff531b add example usage
Signed-off-by: getlarge <ed@getlarge.eu>
2020-12-17 18:06:01 +01:00
getlarge
54ecf63a82 update contact link
Signed-off-by: getlarge <ed@getlarge.eu>
2020-12-17 18:06:01 +01:00
getlarge
f5c2e92c69 update tendermint version in docker compose
Signed-off-by: getlarge <ed@getlarge.eu>
2020-12-17 18:06:01 +01:00
getlarge
4b0d5c40b6 test delegated signature
Signed-off-by: getlarge <ed@getlarge.eu>
2020-12-17 18:06:01 +01:00
getlarge
b2e4ef55bf add delegateSignTransaction static method
Signed-off-by: getlarge <ed@getlarge.eu>
2020-12-17 18:06:00 +01:00
David Dashyan
f08ea00142
Merge pull request #302 from bigchaindb/fix-npm-release
Release 4.1.2
2020-05-12 10:20:02 +00:00
David Dashyan
34233584e1
Release 4.1.2
Fixing messed up 4.1.1 release.

Signed-off-by: David Dashyan <mail@davie.li>
2020-03-11 23:06:25 +03:00
Manolo
ea572804e3
Merge pull request #293 from bigchaindb/add-release-process
Document the release process and update the "release-it" options
2019-09-26 10:49:05 +02:00
Jürgen Eckel
d4dae793e9
Merge pull request #287 from bigchaindb/update-dependencies
Update some package dependencies
2019-09-25 22:35:59 +02:00
Troy McConaghy
667e2c9c71 Update release-it to 12.2.0
Signed-off-by: Troy McConaghy <troy@bigchaindb.com>
2019-05-23 09:20:05 +02:00
Troy McConaghy
5a966f6ab2 Update "release" command. Document release process
Signed-off-by: Troy McConaghy <troy@bigchaindb.com>
2019-05-23 09:18:59 +02:00
manolodewiner
a3d1824a03 Release 4.1.1 2019-04-30 09:58:40 +02:00
Jürgen Eckel
ba81d1b9be
Merge pull request #286 from bigchaindb/update-dependencies
Update tendermint version && dependencies to latest version
2019-04-29 10:05:30 +02:00
manolodewiner
69e9814ba5 update tendermint version && dependencies to latest version
Signed-off-by: manolodewiner <manolosingular@gmail.com>
2019-04-27 18:14:57 +02:00
Troy McConaghy
b37bdcded5
Merge pull request #273 from bigchaindb/update-emails
Update emails
2018-12-11 20:34:05 +01:00
Troy McConaghy
1fe3d3e08d dev --> devs@bigchaindb.com 2018-12-11 20:28:10 +01:00
Troy McConaghy
4fbcdc19c5 Point Code of Contuct page to main BDB repo 2018-12-11 20:26:57 +01:00
Troy McConaghy
f9570378d2 Change Travis CI URLs to use .com 2018-12-11 20:25:16 +01:00
Jernej Pregelj
c33724e3bf string fixes 2018-11-06 11:46:24 +01:00
Jernej Pregelj
561a2960b7
Merge pull request #265 from DavidEdwards/fix-buffer-crash
Wrap Uint8Array in a Buffer
2018-11-06 11:45:58 +01:00
David Edwards
b7a9c960a2 Should not use deprecated constructor. Use Buffer.from. 2018-11-06 11:00:35 +01:00
David Edwards
e4d0efd967 Fixes #264. This wraps the given Uint8Array in a Buffer so that it doesn't cause a crash in base-x. 2018-11-06 10:10:53 +01:00
Troy McConaghy
994c8ef163
Merge pull request #251 from ttmc/update-docs-re-testnet
Update docs, anticipating upcoming testnet changes
2018-09-26 13:20:24 +02:00
Troy McConaghy
4fbac054b1 Remove testnet-specific subdomain & headers 2018-09-13 15:17:39 +02:00
Troy McConaghy
15e50ba96e Remove old testnet information 2018-09-13 14:41:30 +02:00
Manolo
21eb6a0850
Merge pull request #243 from bigchaindb/greenkeeper/babel-loader-8.0.1
Update babel-loader to the latest version 🚀
2018-09-05 12:25:42 +02:00
greenkeeper[bot]
b30bdfddbd chore(package): update babel-loader to version 8.0.1 2018-09-01 21:57:04 +00:00
Manolo
78ebbe3d6d
Merge pull request #242 from bigchaindb/greenkeeper/babel-loader-8.0.0
Update babel-loader to the latest version 🚀
2018-08-31 15:36:00 +02:00
Jernej Pregelj
885c2478ad
Merge pull request #241 from bigchaindb/remove-votes-api
remove votes endpoint
2018-08-31 15:05:44 +02:00
Manolo
6db30fda33
Merge branch 'master' into greenkeeper/babel-loader-8.0.0 2018-08-31 14:58:00 +02:00
Manolo
355dd62a60
Merge branch 'master' into remove-votes-api 2018-08-31 14:56:14 +02:00
Manolo
ffe25a6d80
Merge pull request #240 from bigchaindb/greenkeeper/babel-eslint-9.0.0
Update babel-eslint to the latest version 🚀
2018-08-31 14:53:39 +02:00
Manolo
3c82ae47da
Merge pull request #239 from manolodewiner/bep-14_roundrobin
Implementation of BEP-14
2018-08-31 14:53:03 +02:00
manolodewiner
a99ccd57f1 remove boolean comparison for numbers & add docs 2018-08-31 14:33:21 +02:00
manolodewiner
f5debab03a small refactor and add tests 2018-08-30 12:26:14 +02:00
manolodewiner
11892a1f6b handle timeout for each request 2018-08-29 16:39:15 +02:00
greenkeeper[bot]
885766520e chore(package): update babel-loader to version 8.0.0 2018-08-28 19:28:06 +00:00
Jernej Pregelj
2afbd3b398 remove votes endpoint 2018-08-28 15:38:36 +02:00
manolodewiner
b30578d9ab remove unused headers 2018-08-28 14:27:53 +02:00
manolodewiner
bd8db702c4 cap backoff time 2018-08-28 14:09:26 +02:00
greenkeeper[bot]
30f7ecd389 chore(package): update babel-eslint to version 9.0.0 2018-08-28 03:25:24 +00:00
manolodewiner
e0cde66749 merge 2018-08-23 17:16:16 +02:00
manolodewiner
ad8a889ecc add and fix tests 2018-08-23 17:14:59 +02:00
Manolo
f4d1f93a5b
Merge branch 'master' into bep-14_roundrobin 2018-08-23 09:43:19 +02:00
manolodewiner
7d978286f5 created model for new connections 2018-08-22 10:10:09 +02:00
Troy McConaghy
80bf01eb55
Merge pull request #235 from ttmc/add-more-licensing-info
Add more licensing info
2018-08-13 13:51:44 +02:00
Troy McConaghy
cc203c514b Reformat LICENSE-docs for readability 2018-08-10 14:50:09 +02:00
Troy McConaghy
54dfcf637f Add SPDX license info strings to all source files 2018-08-10 12:49:26 +02:00
Troy McConaghy
27509dcb89 Add LICENSE-docs file, and reference it in README.md 2018-08-10 12:28:17 +02:00
Troy McConaghy
4555e251e5 Remove "coding: utf-8" line in conf.py: not needed in Python 3 files 2018-08-10 12:22:08 +02:00
Manolo
124586dcbc
Merge pull request #234 from bigchaindb/greenkeeper/js-sha3-0.8.0
Update js-sha3 to the latest version 🚀
2018-08-06 10:30:09 +02:00
greenkeeper[bot]
5a88c03513 fix(package): update js-sha3 to version 0.8.0 2018-08-05 07:37:40 +00:00
Jernej Pregelj
9f0ef2525b
Merge pull request #232 from innoprenuer/master
updated driver version to 4.1.0
2018-07-20 14:10:34 +02:00
Manan Patel
3710992441 updated driver version to 4.1.0 2018-07-20 14:02:40 +02:00
Jernej Pregelj
62629df926
Merge pull request #225 from nemaniarjun/cov95
WIP: test-coverage-95
2018-07-20 11:06:44 +02:00
Arjun Nemani
5a9f3905c7 Add tests for sanitize.js
Installs rewire from npm and use it to test functions
in sanitize.js

Part of https://github.com/bigchaindb/js-bigchaindb-driver/issues/220
2018-07-19 21:24:12 +05:30
Arjun Nemani
a3be6c63a6 Fix sanitize array filter
The code for filtering with array has a small mistake,
where it checks if the "key" of the object is included in
the filter array instead of the "value" at that key.

Part of https://github.com/bigchaindb/js-bigchaindb-driver/issue/220
2018-07-19 21:23:57 +05:30
Arjun Nemani
074b4f0871 Add test for baseRequest.js
This commit adds tests for baseRequest,
with the aim to improve the code coverage of the
whole repo.

Part of https://github.com/bigchaindb/js-bigchaindb-driver/issues/220
2018-07-19 21:20:08 +05:30
Arjun Nemani
48f7584374 Fix connection test
This commit fixes the "Payload thrown at incorrect API_PATH"
test, it uses the proper way to check async error throws,
taken from ava.js docs. Done with the aim to increase the
coverage and to ensure working tests. Added "transform-runtime"
to .babelrc to enable "await/async" syntax".

Part of https://github.com/bigchaindb/js-bigchaindb-driver/issues/220
2018-07-19 20:23:12 +05:30
Arjun Nemani
64713d3742 Add tests for format_text.js
This commit adds tests for format_text,
with the aim to improve the code coverage of the
whole repo.

Part of https://github.com/bigchaindb/js-bigchaindb-driver/issues/220
2018-07-19 20:23:12 +05:30
Jernej Pregelj
aaad21895f
Merge pull request #227 from dmvt/reduce-driver-to-less-than-1-MB
reduces development driver size to ~683k by removing vendor sourceMaps
2018-07-18 15:41:32 +02:00
Dan Matthews
1b21c28d7d removes -w flag from the build:dist 2018-07-18 09:37:13 -04:00
Dan Matthews
28d9cfc0fa reduces development driver size to ~683k by removing vendor sourceMaps 2018-07-17 10:33:58 -04:00
Manolo
b315b8fe68
Merge pull request #231 from bigchaindb/greenkeeper/babel-eslint-8.2.6
chore(package): update babel-eslint to version 8.2.6
2018-07-17 13:40:37 +02:00
Manolo
8628a91c49
Merge pull request #230 from bigchaindb/greenkeeper/documentation-8.0.1
chore(package): update documentation to version 8.0.1
2018-07-17 13:40:23 +02:00
manolodewiner
9f727b55d9 Merge branch 'master' into greenkeeper/babel-eslint-8.2.6 2018-07-17 12:03:12 +02:00
manolodewiner
180a7c2dc0 Merge branch 'master' into greenkeeper/documentation-8.0.1 2018-07-17 11:59:50 +02:00
Manolo
08c826de25
Merge pull request #229 from bigchaindb/greenkeeper/webpack-4.16.1
Greenkeeper/webpack 4.16.1
2018-07-17 11:43:40 +02:00
manolodewiner
4a38192f76 Merge branch 'master' into greenkeeper/webpack-4.16.1 2018-07-17 11:31:50 +02:00
Manolo
944f047060
Merge pull request #228 from bigchaindb/update-tendermint
Update tendermint and mongo version
2018-07-17 11:30:15 +02:00
manolodewiner
ba4b488dca update tendermint and mongo version 2018-07-17 11:15:53 +02:00
greenkeeper[bot]
9f5ac7445b chore(package): update webpack to version 4.16.1 2018-07-16 09:13:18 +00:00
greenkeeper[bot]
2d8bdcf311 chore(package): update documentation to version 8.0.1 2018-07-16 03:58:50 +00:00
greenkeeper[bot]
71b2f0d934 chore(package): update babel-eslint to version 8.2.6 2018-07-12 14:27:44 +00:00
Jernej Pregelj
ea4f9e4464
Merge pull request #219 from innoprenuer/master
removed redundant getTransaction func calls
2018-07-09 13:36:54 +02:00
Manan Patel
28bcc02f30 removed redundant getTransaction func calls 2018-07-06 16:51:10 +02:00
innoprenuer
96fd99e076
Merge pull request #218 from innoprenuer/master
updated examples with latest api functions
2018-07-06 14:58:58 +02:00
Manan Patel
fadc1bd567 updated examples with latest api functions 2018-07-06 14:47:32 +02:00
9dfd7e20bf
Release 4.1.0 2018-07-05 14:18:32 +02:00
6376e538ab
Merge pull request #180 from tnguyen42/patch-4
Minor corrections and details
2018-07-05 14:16:47 +02:00
64b3272dd0
Merge pull request #217 from bigchaindb/feature/api-doc
update API doc
2018-07-05 14:14:26 +02:00
3fc4958f63
update API doc 2018-07-05 13:53:15 +02:00
6a637f33e2
Merge pull request #216 from bigchaindb/feature/package-updates
bump dependencies
2018-07-05 13:47:53 +02:00
4a212b29be
bump dependencies 2018-07-05 12:52:39 +02:00
56166698f1
Merge pull request #215 from bigchaindb/greenkeeper/babel-plugin-add-module-exports-0.3.1
chore(package): update babel-plugin-add-module-exports to version 0.3.1
2018-07-05 12:45:03 +02:00
cbd2536cca
Merge pull request #214 from bigchaindb/greenkeeper/babel-eslint-8.2.5
chore(package): update babel-eslint to version 8.2.5
2018-07-05 12:44:50 +02:00
1bbfe7b27b
Merge pull request #213 from bigchaindb/greenkeeper/webpack-4.15.0
chore(package): update webpack to version 4.15.0
2018-07-05 12:40:53 +02:00
greenkeeper[bot]
9189ba7b52 chore(package): update webpack to version 4.15.0 2018-07-04 20:27:40 +00:00
greenkeeper[bot]
b4e273de75 chore(package): update babel-plugin-add-module-exports to version 0.3.1
Closes #212
2018-07-02 21:17:14 +00:00
Manolo
5c977696ba
Merge pull request #197 from bigchaindb/adding_asyncMethod
adding async method
2018-06-28 17:30:55 +02:00
Manolo
3dbee074a9
Merge pull request #207 from bigchaindb/greenkeeper/eslint-5.0.0
Update eslint to the latest version 🚀
2018-06-25 12:02:18 +02:00
df0b3d5888
modify eslint glob pattern 2018-06-25 11:42:17 +02:00
greenkeeper[bot]
156fc5ffcb chore(package): update babel-eslint to version 8.2.5 2018-06-23 16:33:15 +00:00
greenkeeper[bot]
409e79e4f3 chore(package): update eslint to version 5.0.0 2018-06-23 08:05:53 +00:00
manolodewiner
9077d6ce34 update docs 2018-06-19 16:58:42 +02:00
manolodewiner
34c82a1ae8 refactor code & add test 2018-06-19 16:52:23 +02:00
a3ff691310
Merge pull request #203 from bigchaindb/fix-copyright-year-in-docs
Problem: Copyright year wrong in docs
2018-06-15 11:45:20 +02:00
Troy McConaghy
d0724b60f5
Problem: Copyright year wrong in docs
Solution: Compute the copyright year when generating the docs
2018-06-14 15:12:45 +02:00
d3630109d3
Release 4.0.2 2018-06-13 17:37:19 +02:00
edcc837cee
Merge pull request #202 from bigchaindb/greenkeeper/webpack-4.12.0
chore(package): update webpack to version 4.12.0
2018-06-13 16:47:03 +02:00
greenkeeper[bot]
aedfe02230
chore(package): update webpack to version 4.12.0 2018-06-13 16:36:41 +02:00
7932c9a1af
Merge pull request #201 from bigchaindb/greenkeeper/webpack-cli-3.0.4
chore(package): update webpack-cli to version 3.0.4
2018-06-13 16:34:20 +02:00
bc8c9f8f98
Merge pull request #200 from bigchaindb/greenkeeper/cross-env-5.2.0
chore(package): update cross-env to version 5.2.0
2018-06-13 16:26:06 +02:00
bf3794d243
Merge pull request #195 from bigchaindb/greenkeeper/sinon-6.0.0
Update sinon to the latest version 🚀
2018-06-13 16:21:45 +02:00
greenkeeper[bot]
d080674c6f chore(package): update cross-env to version 5.2.0 2018-06-13 13:54:29 +00:00
amed83
d812e64b30 adding async method 2018-06-12 14:42:42 +02:00
greenkeeper[bot]
387a9be5af chore(package): update webpack-cli to version 3.0.4 2018-06-12 12:01:28 +00:00
greenkeeper[bot]
b089d4b009 chore(package): update sinon to version 6.0.0 2018-06-11 06:44:49 +00:00
Manolo
206e4cec5f
Merge pull request #189 from bigchaindb/greenkeeper/nyc-12.0.1
Update nyc to the latest version 🚀
2018-06-06 09:09:52 +02:00
Manolo
437de5ffa3
Merge pull request #190 from bigchaindb/greenkeeper/webpack-cli-3.0.0
Update webpack-cli to the latest version 🚀
2018-06-06 09:09:14 +02:00
Manolo
eb1559d2f9
Merge pull request #192 from bigchaindb/greenkeeper/documentation-8.0.0
Update documentation to the latest version 🚀
2018-06-06 09:08:50 +02:00
Manolo
2b665dc5ca
Merge pull request #193 from bigchaindb/fixing_forEach
changed forEach method
2018-06-06 09:06:00 +02:00
amed83
2021639139 changeing bad nameed variable 2018-06-05 16:47:17 +02:00
amed83
5993c4cd6b changed forEach method 2018-06-05 15:14:15 +02:00
greenkeeper[bot]
446583d019 chore(package): update documentation to version 8.0.0 2018-06-04 19:01:24 +00:00
greenkeeper[bot]
7d68195c74 chore(package): update webpack-cli to version 3.0.0 2018-06-02 14:40:05 +00:00
greenkeeper[bot]
9642928e75 chore(package): update nyc to version 12.0.1 2018-06-01 22:19:32 +00:00
Manolo
b62471a709
Merge pull request #182 from bigchaindb/fix-integration-test
Problem: Test "Valid TRANSFER transaction with multiple Ed25519 inputs..." failing
2018-06-01 14:30:15 +02:00
manolodewiner
4639acbd34 resolve promise to avoid invalid input 2018-05-23 14:33:45 +02:00
Thanh-Quy Nguyen
80811b8c7a
Minor corrections and details
- Inconsistency corrected between conn and bdb at the beginning, while they are the same object
- Asset Creation and Transfer: Cleaned a little useless code that made the end of it not working (returning res.id instead of res... but the (res) arrow function block was an unnecessary step)
- Websocket example: added a precision for the testnet case requiring SSL and port 443
2018-05-22 21:07:38 +02:00
9163284b4a
Merge pull request #178 from bigchaindb/greenkeeper/lint-staged-7.1.2
chore(package): update lint-staged to version 7.1.2
2018-05-22 11:19:39 +02:00
Manolo
5f32d685c1
Merge pull request #177 from bigchaindb/greenkeeper/documentation-7.0.0
Update documentation to the latest version 🚀
2018-05-22 09:06:18 +02:00
greenkeeper[bot]
36f88bc712 chore(package): update documentation to version 7.0.0 2018-05-22 05:05:48 +00:00
greenkeeper[bot]
bb44ec4d2e chore(package): update lint-staged to version 7.1.2 2018-05-21 07:39:40 +00:00
2ecc484ec8
Release 4.0.1 2018-05-14 18:08:52 +02:00
5c106a2ff3
Merge pull request #173 from bigchaindb/fix/documentation
Readme & dev updates
2018-05-14 18:00:03 +02:00
81ef5978b8
API docs & dev updates
* new command: npm run doc, for generating the API.md file
* new command: npm run dev, for live watching webpack
* JSdoc: make all methods public by default, selectively make some private
* JSdoc: organize all methods under their class
* linting fixes
* package updates
2018-05-14 17:14:40 +02:00
691fadfd98
readme updates
* update TOC
* tweak documentation links
* remnove IPDB references
2018-05-14 14:06:44 +02:00
4570b24a5d
Merge pull request #172 from bigchaindb/fix/travis
Fix Travis
2018-05-14 13:51:47 +02:00
fbb9b9536f
test current and last 2 major Node.js versions 2018-05-14 13:07:02 +02:00
03014b08f0
ignore vscode settings 2018-05-14 13:05:45 +02:00
3527b1cff5
bump tendermint version
* just like in python driver: 4830b2b6cf
* delete unused travis script
2018-05-14 12:54:49 +02:00
e0d82b8778
ci script tweaks 2018-05-11 16:08:58 +02:00
364f0a25d3
ESlint fixes
* use local eslint on Travis
* lint fixes for examples
2018-05-11 15:49:16 +02:00
a149ef9125
delete yarn.lock 2018-05-11 15:43:51 +02:00
b6a1a13bf8
bump Node.js version, build current and last version 2018-05-11 15:40:34 +02:00
Manolo
0c8a9c6c4c
Change localhost to test network 2018-05-11 10:36:01 +02:00
Manolo
b2d34c87a2
Merge pull request #142 from michielmulders/docs-examples
Examples for JS driver
2018-05-11 10:34:36 +02:00
ba43fe48bb
Merge pull request #163 from bigchaindb/test-coverage
Increase test coverage
2018-05-09 22:54:13 +02:00
Manolo
5cb24cff84
Fix BigchainDB version compatibility 2018-04-19 12:26:49 +02:00
Jernej Pregelj
6c275da1bc
Merge pull request #162 from bigchaindb/format-docs
Format docs
2018-04-09 14:39:02 +02:00
manolodewiner
c127b1c2a9 text improvement in readme 2018-04-04 10:44:15 +02:00
manolodewiner
e2da49751c postTransaction --> postTransactionCommit in README 2018-04-04 10:27:23 +02:00
manolodewiner
22e0a59dcd test Sha256Condition 2018-04-04 10:16:39 +02:00
manolodewiner
107c8b0d6e version 4.0 added to breaking changes 2018-04-03 10:47:00 +02:00
manolodewiner
9023d061dd include BigchainDB2.0 in README 2018-04-03 10:43:25 +02:00
Manolo
7699e14705
Merge pull request #160 from bigchaindb/greenkeeper/sinon-5.0.0
Update sinon to the latest version 🚀
2018-04-03 08:28:08 +02:00
Manolo
7079b752e0
Merge branch 'master' into greenkeeper/sinon-5.0.0 2018-04-03 08:23:41 +02:00
Manolo
618c2526f8
Merge pull request #159 from bigchaindb/tendermint-tx-fixed
Update driver in order to be compatible with BigchainDB2.0
2018-03-29 19:29:56 +02:00
Manolo
a905260e07
Merge branch 'master' into tendermint-tx-fixed 2018-03-29 19:26:17 +02:00
Jernej Pregelj
bc32780630 Merge branch 'tendermint-tx-fixed' of https://github.com/bigchaindb/js-bigchaindb-driver into tendermint-tx-fixed 2018-03-29 19:22:23 +02:00
manolodewiner
55dbaf878a remove driver container 2018-03-29 19:18:27 +02:00
manolodewiner
be9980e01c travis script typo 2018-03-29 19:14:37 +02:00
manolodewiner
57bb70074e node version updated 2018-03-29 19:11:03 +02:00
Jernej Pregelj
bd8fbec5fd merge 2018-03-29 19:02:46 +02:00
Jernej Pregelj
150b625997 npm updates 2018-03-29 18:58:55 +02:00
manolodewiner
3d232c6fc2 test passing 2018-03-29 18:57:12 +02:00
manolodewiner
67b048a965 Revert "reformat docs"
This reverts commit 5a96c7fdbe.
2018-03-29 17:57:55 +02:00
manolodewiner
0d091d0a31 docker files created 2018-03-29 16:45:00 +02:00
manolodewiner
5a96c7fdbe reformat docs 2018-03-29 11:40:14 +02:00
manolodewiner
51ffdfe0b9 bigchaindb master image for travis 2018-03-28 17:04:45 +02:00
manolodewiner
0d9d04eb8b added versions numbers 2018-03-28 17:03:26 +02:00
manolodewiner
99a049056b fix tests 2018-03-27 16:44:59 +02:00
manolodewiner
b4e31fe786 docs updated 2018-03-27 09:07:31 +02:00
manolodewiner
abe1c89025 test integration failing 2018-03-26 12:15:36 +02:00
greenkeeper[bot]
2f2169d156 chore(package): update sinon to version 5.0.0 2018-03-21 18:19:28 +00:00
manolodewiner
2451ed2ae6 update endpoints 2018-03-21 11:30:54 +01:00
Manolo
a1b25b1140
Merge pull request #154 from bigchaindb/greenkeeper/webpack-4.0.0
Update webpack to the latest version 🚀
2018-03-05 12:01:38 +01:00
5affc1f85d
Merge pull request #156 from bigchaindb/greenkeeper/fetch-ponyfill-6.0.0
Update fetch-ponyfill to the latest version 🚀
2018-03-02 14:08:52 +01:00
f1b0c31b3a
Merge pull request #153 from bigchaindb/crypto-conditions-example
Add crypto conditions example
2018-03-02 14:07:38 +01:00
6a90cf4b9c
Merge pull request #151 from bigchaindb/greenkeeper/lint-staged-7.0.0
Update lint-staged to the latest version 🚀
2018-03-02 14:05:25 +01:00
greenkeeper[bot]
fa6cae6487 fix(package): update fetch-ponyfill to version 6.0.0 2018-03-02 13:01:16 +00:00
manolodewiner
c3e1244e52 unique-fulfillment and hash&sign 2018-03-01 12:22:36 +01:00
greenkeeper[bot]
ba37c1e37f chore(package): update webpack to version 4.0.0 2018-02-25 04:09:44 +00:00
manolodewiner
61e9697569 correct typo 2018-02-23 14:52:39 +01:00
manolodewiner
d0559e5c38 add crypto conditions example 2018-02-23 14:22:52 +01:00
greenkeeper[bot]
069405d317 chore(package): update lint-staged to version 7.0.0 2018-02-21 12:23:11 +00:00
Manolo
428edad6eb
Correct typo 2018-02-21 10:33:47 +01:00
Manolo
e1e2950dd9
Merge pull request #146 from bigchaindb/greenkeeper/release-it-7.0.0
Update release-it to the latest version 🚀
2018-02-09 09:43:06 +01:00
Manolo
824daaeccc
Change references to IPDB 2018-02-08 14:04:51 +01:00
Manolo
ffcd0163fa
Change references from IPDB to test network 2018-02-08 14:03:00 +01:00
greenkeeper[bot]
f7278c5eff chore(package): update release-it to version 7.0.0 2018-02-07 23:14:56 +00:00
Manolo
e4871728cc
Merge pull request #145 from bigchaindb/greenkeeper/fetch-ponyfill-5.0.0
Update fetch-ponyfill to the latest version 🚀
2018-02-06 14:54:41 +01:00
greenkeeper[bot]
90dbc20ded fix(package): update fetch-ponyfill to version 5.0.0 2018-02-04 12:26:56 +00:00
Manolo
1a6db37fc9
Merge pull request #144 from bigchaindb/greenkeeper/ava-0.25.0
Update ava to the latest version 🚀
2018-01-30 11:17:18 +01:00
Manolo
6db5b8fedc
Merge pull request #141 from bigchaindb/greenkeeper/release-it-6.0.0
Update release-it to the latest version 🚀
2018-01-30 11:17:02 +01:00
greenkeeper[bot]
5daea889fa chore(package): update ava to version 0.25.0 2018-01-26 15:10:48 +00:00
Michiel Mulders
c7b55e5ad3 Fix note to top of readme 2018-01-23 17:12:19 +01:00
Michiel Mulders
745ddf9527 Update structure eslint test 2018-01-20 22:50:17 +01:00
Michiel Mulders
0a7e207fef Finished examples - experimenting with websocket 2018-01-20 22:19:23 +01:00
Michiel Mulders
87f36946f0 Basic usage async example 2018-01-20 21:38:59 +01:00
Michiel Mulders
01deae78cd example seed-func ready 2018-01-20 16:41:05 +01:00
Michiel Mulders
10fab5323a Small fix query-all-example 2018-01-20 15:22:07 +01:00
Michiel Mulders
1aa295830d First example v2 2018-01-20 14:45:57 +01:00
Michiel Mulders
2deba0cad8 First example 2018-01-20 14:25:15 +01:00
greenkeeper[bot]
3d62df3dc5 chore(package): update release-it to version 6.0.0 2018-01-19 21:01:49 +00:00
Manolo
c371e3bfad
Clarify 'aliceOutput' in docs 2018-01-18 11:35:02 +01:00
Manolo
2738f6bdef
Merge pull request #135 from bigchaindb/transaction-one-file
Transaction folder to one file
2018-01-18 08:48:12 +01:00
manolodewiner
072edb054c fix test 2018-01-17 09:20:04 +01:00
manolodewiner
015bf1b07f remove this 2018-01-16 09:09:36 +01:00
manolodewiner
843d85bc03 test failing 2018-01-15 18:11:16 +01:00
manolodewiner
3725afa4a0 static methods 2018-01-15 15:42:34 +01:00
Manolo
633a0562fe
Merge pull request #131 from bigchaindb/greenkeeper/js-sha3-0.7.0
Update js-sha3 to the latest version 🚀
2018-01-15 14:14:04 +01:00
Manolo
43a67ae26e
Merge pull request #137 from bigchaindb/greenkeeper/decamelize-2.0.0
Update decamelize to the latest version 🚀
2018-01-15 14:13:26 +01:00
greenkeeper[bot]
674d1022de fix(package): update decamelize to version 2.0.0 2018-01-08 19:17:06 +00:00
manolodewiner
4dd006b8cb fix issues 2018-01-04 10:15:45 +01:00
Jernej Pregelj
0d1bc2209b Release 3.2.0 2017-12-21 10:15:02 +01:00
manolodewiner
b05dc84ff8 80chars rule 2017-12-20 15:07:23 +01:00
Manolo
879ae68d0c
Merge pull request #125 from bigchaindb/transfer-multiple-inputs-rebase
Transfer multiple inputs rebase
2017-12-20 12:53:04 +01:00
manolodewiner
2348a49965 older versions readme explanation 2017-12-20 11:32:34 +01:00
manolodewiner
e745b5948d Breaking changes docs added 2017-12-19 16:56:16 +01:00
manolodewiner
ebf5f6a408 small correction when changing to camelcase 2017-12-19 15:57:36 +01:00
Manolo
bc574c2b9d
camelcase output_index 2017-12-19 15:17:10 +01:00
Manolo
c169eb5d48
Resolve merge 2017-12-18 15:14:03 +01:00
8f5864e32a
Merge pull request #130 from bigchaindb/greenkeeper/lint-staged-6.0.0
Update lint-staged to the latest version 🚀
2017-12-12 12:25:14 +01:00
Manolo
a3012bcc34
Correct mistake in searchMetadata example 2017-12-05 16:10:43 +01:00
greenkeeper[bot]
4ec535670c fix(package): update js-sha3 to version 0.7.0 2017-12-01 13:08:39 +00:00
greenkeeper[bot]
4f90fb30d5 chore(package): update lint-staged to version 6.0.0 2017-12-01 04:40:13 +00:00
e432ad2182
Merge pull request #128 from gitter-badger/gitter-badge
Add a Gitter chat badge to README.md
2017-11-30 12:17:10 +01:00
ddacac9eee
Merge pull request #127 from bigchaindb/greenkeeper/ava-0.24.0
Update ava to the latest version 🚀
2017-11-30 12:14:11 +01:00
002b1bf3a0
gitter badge positioning 2017-11-30 12:12:08 +01:00
The Gitter Badger
c8fff0245e Add Gitter badge 2017-11-29 09:18:18 +00:00
greenkeeper[bot]
91d9cf5663 chore(package): update ava to version 0.24.0 2017-11-27 19:46:24 +00:00
Jernej Pregelj
0960a5adb4 Release 3.1.1 2017-11-27 17:07:34 +01:00
manolodewiner
1076d2d2ab merge master 2017-11-27 15:36:34 +01:00
Jernej Pregelj
84bbd46d01 Release 3.1.0 2017-11-27 15:35:47 +01:00
Manolo
1044a01fb4
Merge pull request #126 from bigchaindb/js-crypto-conditions
five-bells-conditions -> js-crypto-conditions
2017-11-27 15:12:33 +01:00
manolodewiner
ad03590347 Merge branch 'search-metadata' 2017-11-27 15:09:34 +01:00
Jernej Pregelj
da4c4a942b js-crypto-conditions -> crypto-conditions 2017-11-27 14:56:11 +01:00
manolodewiner
ba7f19448c Merge branch 'master' into search-metadata 2017-11-27 14:47:34 +01:00
Jernej Pregelj
7fbac23dc2 five-bells-conditions -> js-crypto-conditions 2017-11-23 16:39:13 +01:00
manolodewiner
1cacace1b7 Metadata search in docs 2017-11-23 16:38:52 +01:00
Jernej Pregelj
6d57f5b2da release-it update 2017-11-23 16:10:33 +01:00
Jernej Pregelj
e4893c36bb
Merge pull request #123 from bigchaindb/greenkeeper/release-it-5.0.0
Update release-it to the latest version 🚀
2017-11-23 12:55:36 +01:00
manolodewiner
6031868245 docs updated to new makeTransferTransaction format 2017-11-23 10:03:23 +01:00
manolodewiner
9f385c440d Add test of transaction with multiple inputs 2017-11-23 10:03:23 +01:00
Rashad Ibrahimov
e0f11ec415 Issue #44 Multiple inputs for transfer transaction 2017-11-23 10:03:23 +01:00
a8250d632c remove yarn
* yarn is usually installed globally and we never call the locally installed version
2017-11-23 10:03:23 +01:00
michielmulders
2df643b8a7 Removed parenthesis in request.js 2017-11-23 10:03:23 +01:00
michielmulders
d05f7ef3e6 Issue 50: remove onlyJsonResponse connection.js 2017-11-23 10:02:28 +01:00
michielmulders
fee4530d5c Revert "Fix Issue 50: connection.js remove onlyJsonResponse"
This reverts commit 3c9ff5c384.
2017-11-23 10:02:28 +01:00
michielmulders
e99b4b9874 Fix Issue 50: connection.js remove onlyJsonResponse 2017-11-23 10:02:28 +01:00
michielmulders
5cdcf3bac1 Removed build dirs from soruce and edited gitignore for the last time 2017-11-23 10:02:01 +01:00
michielmulders
76614e9e84 Change gitignore with _build 2017-11-23 10:02:01 +01:00
michielmulders
13632c62bc Ignore doc/_build instead of doc/build 2017-11-23 10:01:45 +01:00
michielmulders
af86eb7f80 Added make hmtl and clean to Makefile 2017-11-23 10:01:26 +01:00
michielmulders
dfe221031e Removed /build and gitignore inside /docs, added /docs/build in main gitignore 2017-11-23 10:01:09 +01:00
michielmulders
16174442d5 Added gitignore to not upload build/ dir 2017-11-23 10:00:40 +01:00
michielmulders
76867e1de7 Moved docs from personal repo to official js Driver repo 2017-11-23 10:00:40 +01:00
vrde
6416718102 Fix eslint errors 2017-11-23 09:55:45 +01:00
Scott Sadler
4f48f1768e add has subcondition to ccJsonLoad test 2017-11-23 09:54:51 +01:00
Scott Sadler
4a349013b2 add additional test for ccJsonLoad 2017-11-23 09:54:51 +01:00
greenkeeper[bot]
fb7dd5580a fix(package): update yarn to version 0.27.5 2017-11-23 09:54:51 +01:00
diminator
132c139899 ignore yarn.lock 2017-11-23 09:54:08 +01:00
Manolo
bb5b4ce05e
Update bigchaindb docker image version to 1.3 2017-11-22 13:54:14 +01:00
greenkeeper[bot]
5686a118fe chore(package): update release-it to version 5.0.0 2017-11-21 22:12:10 +00:00
manolodewiner
dd2a52bf1f search metadata field 2017-11-21 16:51:31 +01:00
a1301861b4
Merge pull request #122 from bigchaindb/greenkeeper/release-it-4.4.1
chore(package): update release-it to version 4.4.1
2017-11-21 16:59:55 +02:00
703d23004f
Merge pull request #121 from bigchaindb/greenkeeper/lint-staged-5.0.0
Update lint-staged to the latest version 🚀
2017-11-21 16:55:06 +02:00
5b0ebbe3a0
Merge pull request #115 from bigchaindb/greenkeeper/ava-0.23.0
Update ava to the latest version 🚀
2017-11-21 16:54:47 +02:00
greenkeeper[bot]
8908e6635a chore(package): update release-it to version 4.4.1
Closes #116
2017-11-15 18:38:46 +00:00
greenkeeper[bot]
3842c48daa chore(package): update lint-staged to version 5.0.0 2017-11-11 08:34:30 +00:00
michielmulders
3b509b5a48 ESLint fixes 2017-11-02 23:16:35 +01:00
michielmulders
42de727882 ESLint fixes 2017-11-02 23:07:34 +01:00
michielmulders
202bf16d09 ESLint fixes 2017-11-02 23:02:12 +01:00
michielmulders
35e1073a2f ESLint fixes 2017-11-02 22:49:01 +01:00
michielmulders
9b05b7354f ESLint fixes 2017-11-02 22:25:26 +01:00
michielmulders
c793ffbb71 ESLint fixes 2017-11-02 21:32:46 +01:00
michielmulders
d7c3276e12 Updated test/transaction/test_transaction.js 2017-11-02 21:19:19 +01:00
michielmulders
2e1c43bf92 ESLint fixes 2017-11-02 21:13:51 +01:00
michielmulders
c8cdf5eadd Changed export statement at index.js 2017-11-02 21:03:40 +01:00
michielmulders
61179c167b Made class for Transaction file 2017-11-02 21:03:15 +01:00
michielmulders
aba3c7d4bc Everything in one file 2017-11-02 20:51:24 +01:00
greenkeeper[bot]
0f0fd3d525 chore(package): update ava to version 0.23.0 2017-10-24 17:34:27 +00:00
Jernej Pregelj
5f2ee8c0d8 Merge pull request #103 from bigchaindb/greenkeeper/sinon-4.0.0
Update sinon to the latest version 🚀
2017-10-16 14:10:40 +02:00
Jernej Pregelj
6c313eac0e Merge pull request #108 from michielmulders/doc-seed-func
Doc seed functionality added
2017-10-16 14:09:48 +02:00
Jernej Pregelj
0b65d3d741 Merge pull request #110 from michielmulders/websocket-api-doc
Websocket api documentation usage added for javascript
2017-10-16 14:09:35 +02:00
Jernej Pregelj
f1d4c47c98 Merge pull request #111 from michielmulders/divisible-assets
Divisible Assets added to Docs
2017-10-16 14:09:08 +02:00
Michiel Mulders
a6606e26ac Merge branch 'master' into doc-seed-func 2017-10-15 18:43:23 +02:00
michielmulders
1dc8bb9883 remove file 2017-10-15 18:39:00 +02:00
Jernej Pregelj
8804998546 Merge branch 'master' into websocket-api-doc 2017-10-15 12:28:24 +02:00
Michiel Mulders
df484832ed added const for declaring objects 2017-10-12 13:40:23 +02:00
michielmulders
8e7c213fb9 Finished divisible asset example 2017-10-09 15:09:23 +02:00
Jernej Pregelj
320a41a30a Merge pull request #105 from bigchaindb/greenkeeper/release-it-3.0.0
Update release-it to the latest version 🚀
2017-10-06 15:09:52 +02:00
Jernej Pregelj
922524e2ed Merge pull request #104 from michielmulders/payloadmessage
#31 Solved throw payload message at baserequest
2017-10-06 15:08:27 +02:00
michielmulders
1d58986039 Merge pull request #109 from michielmulders/spent-vs-unspent
Spent vs unspent merge
2017-10-06 13:23:21 +02:00
michielmulders
c46dde75ee small fix: removed ';' 2017-09-30 19:55:06 +02:00
michielmulders
6d5224601f nodejs version added to docs 2017-09-30 19:54:32 +02:00
michielmulders
370171adf7 Small fix hmtl code 2017-09-30 19:54:06 +02:00
michielmulders
c606f64abe Webpage for seeing txs from event stream api added 2017-09-30 19:53:15 +02:00
michielmulders
f4333a92c1 Test added for testing payload thrown at incorrect API_PATH 2017-09-30 19:18:50 +02:00
michielmulders
2fa812940a Added information and code about spent vs unspent transactions 2017-09-28 16:08:41 +02:00
michielmulders
49fe2e879e Added sentence to inform that a seed is not obligatory 2017-09-28 13:33:19 +02:00
michielmulders
25054cc136 Small update to seed func docs 2017-09-28 13:16:01 +02:00
michielmulders
791de0d760 Seed Functionality integrated in docs 2017-09-28 13:15:40 +02:00
michielmulders
22bebc7e2f Merge pull request #1 from bigchaindb/master
Update master to new version
2017-09-28 11:24:25 +02:00
michielmulders
ad89f6f89c Merge pull request #106 from michielmulders/basic-usage-example-fix-code
Small code change - fix
2017-09-28 09:47:50 +02:00
michielmulders
b77d296069 Writing test for baserequest 2017-09-27 15:38:52 +02:00
michielmulders
f82cbd6526 Writing test for baserequest 2017-09-27 15:37:49 +02:00
Tim Daubenschütz
e1be5ba598 Merge pull request #107 from bigchaindb/updated-comp-matrix
Updated compatability for BDB-server 1.1
2017-09-27 15:33:42 +02:00
tim
7cb60a7dc0 Updated compatability for BDB-server 1.1 2017-09-27 15:23:46 +02:00
michielmulders
366a46f8a7 Small extra fix in usage example 2017-09-27 14:35:11 +02:00
michielmulders
c939977c90 Small code change - fix 2017-09-27 14:21:09 +02:00
greenkeeper[bot]
6703fd8839 chore(package): update release-it to version 3.0.0 2017-09-27 05:09:47 +00:00
michielmulders
ce9e88bac3 Fixed for TravisCI 2017-09-26 16:29:52 +02:00
michielmulders
42c037c6ac Trying to match TravisCI Criteria 2017-09-26 16:25:07 +02:00
michielmulders
823d340d61 Updated errorObject to match TravisCI criteria 2017-09-26 16:19:36 +02:00
michielmulders
6c01d37576 Solved throw payload message at baserequest 2017-09-26 16:05:25 +02:00
greenkeeper[bot]
fd75499f24 chore(package): update sinon to version 4.0.0 2017-09-26 09:40:21 +00:00
michielmulders
db4054e1b2 Merge pull request #102 from michielmulders/master
Small cleanup for js-docs
2017-09-22 11:09:32 +02:00
michielmulders
f2fbdc79ce Small cleanup fixes 2017-09-22 11:06:33 +02:00
Tim Daubenschütz
b97cce72f9 Update README.md 2017-09-22 10:27:04 +02:00
Tim Daubenschütz
0d91af5d8f Add docs to readme 2017-09-22 10:26:14 +02:00
Tim Daubenschütz
e34917ea2b Add variable definition 2017-09-22 10:15:02 +02:00
michielmulders
d284ced256 Tried to change permissions of all files to 664 2017-09-22 10:15:02 +02:00
michielmulders
4eae98e463 Added requested changes and did small code change at the end. File permissions not yet changed 2017-09-22 10:15:02 +02:00
michielmulders
146f1f5e13 IPDB conn added and commented Divisible assets 2017-09-22 10:15:02 +02:00
michielmulders
431da5ac95 revert baserequest payload issue 2017-09-22 10:14:35 +02:00
michielmulders
f2e7e1606b Completed basic usage example 2017-09-22 10:14:24 +02:00
michielmulders
dfaf97e5ce Basic usage examples added, not completed 2017-09-22 10:14:24 +02:00
michielmulders
6f6c21dacf Created and updated page with BigchainDB JS Driver info 2017-09-22 10:14:24 +02:00
7f532ee94f remove yarn
* yarn is usually installed globally and we never call the locally installed version
2017-09-22 10:14:24 +02:00
greenkeeper[bot]
4102ef8c21 chore(package): update babel-eslint to version 8.0.0 2017-09-22 10:14:24 +02:00
michielmulders
202ae6060b Removed parenthesis in request.js 2017-09-22 10:14:24 +02:00
michielmulders
7ac13b2045 Issue 50: remove onlyJsonResponse connection.js 2017-09-22 10:14:24 +02:00
greenkeeper[bot]
cce49f1d12 chore(package): update ava to version 0.22.0 2017-09-22 10:14:24 +02:00
michielmulders
a2ff15e282 Update index.rst for testing purpose automated 2017-09-22 10:14:24 +02:00
michielmulders
f0fda97057 Updating index.rst for testing new webhook 2017-09-22 10:14:24 +02:00
michielmulders
a5509a0171 Revert "Fix Issue 50: connection.js remove onlyJsonResponse"
This reverts commit 3c9ff5c384.
2017-09-22 10:14:24 +02:00
michielmulders
5ec5df7e1d Fix Issue 50: connection.js remove onlyJsonResponse 2017-09-22 10:14:24 +02:00
michielmulders
484a3eb608 Issue 57: mv connection/index.js connection.js && rm connection + fix all breaking imports) 2017-09-22 10:14:24 +02:00
michielmulders
4931b62e8e Removed build dirs from soruce and edited gitignore for the last time 2017-09-22 10:14:23 +02:00
michielmulders
c8de30ba57 Change gitignore with _build 2017-09-22 10:14:23 +02:00
michielmulders
178cc116f5 Ignore doc/_build instead of doc/build 2017-09-22 10:14:23 +02:00
michielmulders
c2f4a6e5e2 Added make hmtl and clean to Makefile 2017-09-22 10:14:23 +02:00
michielmulders
c1ddbf479a Removed /build and gitignore inside /docs, added /docs/build in main gitignore 2017-09-22 10:14:23 +02:00
michielmulders
f3df9ed6c7 Added gitignore to not upload build/ dir 2017-09-22 10:14:23 +02:00
michielmulders
b0b0d157cb Moved docs from personal repo to official js Driver repo 2017-09-22 10:14:23 +02:00
greenkeeper[bot]
4154078305 chore(package): update sinon to version 3.0.0 2017-09-22 10:14:23 +02:00
greenkeeper[bot]
ceedf91774 fix(package): update query-string to version 5.0.0 2017-09-22 10:14:23 +02:00
greenkeeper[bot]
3c0209f3cd chore(package): update ava to version 0.21.0 2017-09-22 10:14:23 +02:00
vrde
d714306c9d Update other docs to version 0.3.0
Close #76. Close #77.
2017-09-22 10:14:23 +02:00
vrde
8048399a0b Release 0.3.0 2017-09-22 10:14:23 +02:00
vrde
6dc11b5455 Update README compatibility matrix 2017-09-22 10:14:22 +02:00
vrde
bb3d478b41 Update BigchainDB docker container for travis to 1.0.0 2017-09-22 10:14:22 +02:00
vrde
2fd3fcf8ce Fix eslint errors 2017-09-22 10:14:22 +02:00
greenkeeper[bot]
d0f4342f6f chore(package): update eslint to version 4.1.1
Closes #64
2017-09-22 10:14:22 +02:00
Scott Sadler
d6e33b807a add has subcondition to ccJsonLoad test 2017-09-22 10:14:22 +02:00
Scott Sadler
51585b1b05 add additional test for ccJsonLoad 2017-09-22 10:14:22 +02:00
Scott Sadler
b665752c8c fulfills.output -> fulfills.output_index 2017-09-22 10:14:22 +02:00
Scott Sadler
f82706ecbb point travis at bigchaindb master 2017-09-22 10:14:22 +02:00
Scott Sadler
529c18a753 remove signature in details and rename subfulfillments to subconditions 2017-09-22 10:14:22 +02:00
greenkeeper[bot]
49c91a0916 fix(package): update yarn to version 0.27.5 2017-09-22 10:14:22 +02:00
diminator
a7b09941e2 ignore yarn.lock 2017-09-22 10:14:22 +02:00
greenkeeper[bot]
d390fda202 chore(package): update ava to version 0.20.0 2017-06-28 14:43:55 +00:00
Tim Daubenschütz
f60585d2d0 Merge pull request #69 from bigchaindb/fix-typo
Fix typo in upgrade guide
2017-06-28 09:50:29 +02:00
tim
4c34f33a82 Fix typo via @ferOnti 2017-06-28 09:42:16 +02:00
Tim Daubenschütz
c83181fe20 Merge pull request #62 from bigchaindb/r-0.2.0
Bump version 0.1.2 => 0.2.0
2017-06-26 18:20:23 +02:00
tim
d2c70f66ed Upgrade guide for v0.2.0 2017-06-26 18:18:56 +02:00
tim
e4c24ef027 Use new docker image 1.0.0rc1 2017-06-26 18:18:56 +02:00
tim
332abb53d2 Bump version 0.1.2 => 0.2.0 2017-06-26 18:18:56 +02:00
vrde
96cd7e0383
Merge branch 'update-readme' 2017-06-26 17:28:56 +02:00
vrde
f40d0b06ba
Simplify README.md and change example 2017-06-26 16:21:47 +02:00
Tim Daubenschütz
017827d0a4 Merge pull request #65 from bigchaindb/greenkeeper/js-sha3-0.6.0
Update js-sha3 to the latest version 🚀
2017-06-26 11:28:24 +02:00
greenkeeper[bot]
3bf3e30b89 fix(package): update js-sha3 to version 0.6.0 2017-06-26 05:09:21 +00:00
vrde
288304624a Merge pull request #59 from bigchaindb/remove-content-type-if-no-body
Fix Content-Type issue
2017-06-23 14:53:43 +02:00
vrde
3d83083ee8
Fix Content-Type issue 2017-06-23 14:31:30 +02:00
Tim Daubenschütz
f63a868bc9 Merge pull request #61 from bigchaindb/threshold-public-keys
Encode public_keys array for threshold conditions
2017-06-23 11:18:56 +02:00
Tim Daubenschütz
516ed7a031 Merge pull request #56 from bigchaindb/browser-bundles
Add all browser bundles (for master)
2017-06-23 11:17:18 +02:00
tim
886ed81f84 Fix browser bundling for webpack 2017-06-23 11:00:22 +02:00
tim
e39c46768d Adjust headings 2017-06-23 11:00:22 +02:00
tim
3fa4b0477d Add codecovfefe 2017-06-23 11:00:22 +02:00
tim
36bdb5f1cc Add sinon.js (mocks) to package.json 2017-06-23 11:00:22 +02:00
tim
f158683563 bundle => bigchaindb-driver 2017-06-23 11:00:22 +02:00
tim
710ffbb487 Minor changes to readme 2017-06-23 11:00:22 +02:00
tim
41eab7feab Fix browser docs for new rls 2017-06-23 11:00:22 +02:00
tim
9e6c2c9e25 Add all browser bundles 2017-06-23 11:00:22 +02:00
Scott Sadler
69c1fa29a2 use includes instead of indexOf 2017-06-23 10:46:31 +02:00
Scott Sadler
96ce4f3941 fix transaction tests 2017-06-23 10:44:55 +02:00
Scott Sadler
b22cf39aa2 public_keys array is a set 2017-06-23 10:30:08 +02:00
Scott Sadler
6fa2b2e7e5 encode public_keys array for threshold conditions 2017-06-23 10:24:23 +02:00
52c3505b32 Merge pull request #60 from bigchaindb/greenkeeper/husky-0.14.0
Update husky to the latest version 🚀
2017-06-22 21:53:44 +02:00
greenkeeper[bot]
6a482120f6 chore(package): update husky to version 0.14.0 2017-06-22 18:24:43 +00:00
libscott
cf53b9da46 Merge pull request #51 from bigchaindb/cc2
Integrate cryptoconditions 2
2017-06-22 07:59:58 -07:00
Scott Sadler
46a05b14d3 bump transaction version to 1.0 2017-06-22 16:17:43 +02:00
Scott Sadler
70681a3085 tests for cryptoconditions 2017-06-22 16:13:59 +02:00
Scott Sadler
e19a37fb78 Merge remote-tracking branch 'origin/master' into cc2 2017-06-22 15:09:42 +02:00
Scott Sadler
9e423dd259 work in progress 2017-06-22 15:09:36 +02:00
Tim Daubenschütz
b8d73b23e7 Merge pull request #39 from bigchaindb/http-api-1.0-rc-changes
Http api 1.0 rc changes
2017-06-21 17:50:49 +02:00
tim
1aa430a15c Adjust float interpretation comment 2017-06-21 16:23:53 +02:00
678a4d565e Merge pull request #41 from bigchaindb/greenkeeper/webpack-3.0.0
Update webpack to the latest version 🚀
2017-06-21 16:18:22 +02:00
Tim Daubenschütz
e4338342f8 Merge pull request #54 from bigchaindb/important-change
Important change
2017-06-21 16:05:20 +02:00
tim
0da90e825f rm () 2017-06-21 16:04:35 +02:00
99b263387c
yarn upgrade 2017-06-21 16:03:38 +02:00
tim
c17d614ab6 Dynamically generated keys for /outputs tests + bool fix 2017-06-21 15:59:28 +02:00
8cd04d647c Merge branch 'master' into greenkeeper/webpack-3.0.0 2017-06-21 15:53:26 +02:00
tim
f77f22b89d final 2017-06-21 15:27:02 +02:00
tim
895b6960b2 ok a last one 2017-06-21 15:19:07 +02:00
tim
5bf7009c3e come on 2017-06-21 15:09:35 +02:00
tim
f007dedd35 hello 2017-06-21 15:06:15 +02:00
4655e371ef Merge pull request #46 from bigchaindb/fix/42
Precommit eslint on staged files only
2017-06-21 13:57:39 +02:00
tim
53071f6316 such importance, wow 2017-06-21 13:50:41 +02:00
4fe121f77c
fix lint-staged eslint running on everything 2017-06-21 13:42:29 +02:00
0c6098fce7
run precommit eslint on staged files only
* closes #42
2017-06-21 13:42:28 +02:00
tim
b883e1f6d9 endpoints => endpoint 2017-06-21 13:27:54 +02:00
tim
1696f7c1ac Test list transaction for an asset id 2017-06-21 13:27:54 +02:00
tim
3671c5758c Test list blocks for a transaction id 2017-06-21 13:27:54 +02:00
tim
8bd602f446 Fix and test outputs endpoint 2017-06-21 13:27:54 +02:00
tim
db10937f9e Add integration test for asset endpoint :diamond: 2017-06-21 13:27:54 +02:00
tim
3fdaf40602 Comply to eslint 🔫 2017-06-21 13:27:54 +02:00
tim
44896b98dc serializeTransactionIntoCanonicalString line length 2017-06-21 13:27:54 +02:00
tim
03c17ef70c Add integration tests 2017-06-21 13:27:54 +02:00
tim
9bc0773b4e Add constants.js 2017-06-21 13:27:54 +02:00
tim
d8cb13ba91 Test Connection._req 2017-06-21 13:27:54 +02:00
tim
d4ea4d6ccd CamelCase for path keys 2017-06-21 13:27:54 +02:00
tim
af49ec1c7a Adjust HTTP API endpoints and test 2017-06-21 13:27:54 +02:00
Tim Daubenschütz
8cde6df907 Merge pull request #52 from bigchaindb/add-codecov
Add codecovfefe
2017-06-21 13:26:48 +02:00
tim
2fa28d7fd1 Add coverage badge 2017-06-21 13:22:25 +02:00
tim
b78e33466f Add codecovfefe 2017-06-21 13:17:00 +02:00
Scott Sadler
ce523e703f load condition details and test transfer and sign 2017-06-21 09:56:51 +02:00
Scott Sadler
35944d6d75 cc2 threshold condition creation 2017-06-21 09:56:51 +02:00
Scott Sadler
07e6584cf4 cc2 ed25519 condition creation 2017-06-21 09:56:51 +02:00
f6be556317 Merge pull request #47 from bigchaindb/feature/code-of-conduct
Add Code of Conduct
2017-06-20 17:45:09 +02:00
25860a43b1 add Code of Conduct
* based on Contributor Covenant
* add our protection for discrimination based on species
2017-06-20 16:37:58 +02:00
Tim Daubenschütz
0d284c75dc Merge pull request #35 from bigchaindb/1.0-rc-compatiblity
Updated data models for 1.0
2017-06-20 15:09:21 +02:00
tim
ede11da4c7 Correct mocking of export default 2017-06-20 14:55:58 +02:00
tim
42b400253b Add sinon.js (mocks) to package.json 2017-06-20 14:14:14 +02:00
tim
ac0a124054 Remove unnecessary returns 2017-06-20 13:34:14 +02:00
tim
3389726cb2 Test against BDB:master 2017-06-20 11:05:20 +02:00
tim
9183205f04 Use rest params in fn definition 2017-06-20 11:04:34 +02:00
tim
ed18384b82 Bump ascribe-eslint-config 2017-06-20 11:04:34 +02:00
tim
b8241589df fulfills.txid => fulfills.transaction_id + tests 2017-06-20 11:04:34 +02:00
tim
a14dbbaebd Add tests for makeOutput 2017-06-20 11:04:34 +02:00
tim
27d8dabd7a Stringify output.amount 2017-06-20 11:04:34 +02:00
tim
0ed3aa39b4 fulfills.txid ==> fulfills.transaction_id 2017-06-20 11:04:34 +02:00
greenkeeper[bot]
ff7d3d4fa6 chore(package): update webpack to version 3.0.0 2017-06-19 17:20:13 +00:00
vrde
f1f52cd1bc
Merge branch 'travis-ci' 2017-06-19 18:48:24 +02:00
vrde
c9dbe9e91d
Add yarn 2017-06-19 18:44:32 +02:00
vrde
1f961d0610
Try new .travis.yml 2017-06-19 17:34:22 +02:00
libscott
839361c1c7 Merge pull request #37 from bigchaindb/non-executable-license
remove +x flag on LICENSE
2017-06-19 03:16:44 -07:00
Scott Sadler
dad655a721 remove +x flag on LICENSE 2017-06-19 11:53:22 +02:00
97 changed files with 5991 additions and 950 deletions

View File

@ -1,31 +1,29 @@
{
"presets": [
"@ava/stage-4",
"@ava/transform-test-files",
"es2015-no-commonjs"
],
"plugins": [
"transform-export-extensions",
"transform-object-assign",
"transform-object-rest-spread"
],
"sourceMaps": true,
"env": {
"bundle": {
"plugins": [
["transform-runtime", {
"polyfill": true,
"regenerator": false
}]
]
},
"cjs": {
"plugins": [
"add-module-exports",
"transform-es2015-modules-commonjs"
]
}
}
"presets": [
[
"@babel/preset-env",
{
"targets": [
"> 0.25%, not dead",
"not IE 11",
"maintained node versions"
]
}
]
],
"plugins": [
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-transform-object-assign",
"@babel/plugin-proposal-object-rest-spread",
[
"@babel/plugin-transform-runtime",
{
"absoluteRuntime": false,
"corejs": 3,
"helpers": true,
"regenerator": true
}
]
],
"sourceMaps": true
}

13
.ci/travis-before-install.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
sudo apt-get update
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
sudo rm /usr/local/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
chmod +x docker-compose
sudo mv docker-compose /usr/local/bin

13
.ci/travis-before-script.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
set -e -x
docker-compose up -d bigchaindb
npm install
gem install cowsay
npm install -g codecov

9
.ci/travis-install.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
set -e -x
docker-compose build --no-cache bigchaindb

View File

@ -1,2 +1,6 @@
dist
node_modules
node_modules
coverage
media
docs
compose

231
.eslintrc.js Normal file
View File

@ -0,0 +1,231 @@
module.exports = {
extends: ['eslint:recommended', 'airbnb-base', 'plugin:import/recommended'],
parser: '@babel/eslint-parser',
parserOptions: { requireConfigFile: false },
env: {
browser: true,
node: true,
},
settings: {
'import/ignore': ['node_modules', '.(scss|css)$', '.(jpe?g|png|gif|svg)'],
},
rules: {
/**
* Possible Errors
* http://eslint.org/docs/rus/#possible-errors
*/
// Allow dangling commas for multiline arrays and objects
// http://eslint.org/docs/rules/comma-dangle
'comma-dangle': [1, 'only-multiline'],
// Warn against use of console for non-error logging
// http://eslint.org/docs/rules/no-console
'no-console': [1, { allow: ['error'] }],
// Allow use of Object.prototypes builtins directly
// http://eslint.org/docs/rules/no-prototype-builtins
'no-prototype-builtins': [0],
/**
* Best Practices
* http://eslint.org/docs/rules/#best-practices
*/
// Allow else clauses after an if with a return
// http://eslint.org/docs/rules/no-else-return
'no-else-return': [0],
// Disallow reassignment of function parameters (but allow assigning to parameter's properties)
// http://eslint.org/docs/rules/no-param-reassign.html
'no-param-reassign': [2, { props: false }],
/**
* Variables
* http://eslint.org/docs/rules/#variables
*/
// Disallow use of variables and classes before they are defined
// http://eslint.org/docs/rules/no-use-before-define
'no-use-before-define': [2, { functions: false, classes: true }],
// Disallow declaration of variables that are not used in the code, unless they are prefixed by
// `ignored` (useful for creating subset objects through destructuring and rest objects)
// http://eslint.org/docs/rules/no-unused-vars
'no-unused-vars': [
2,
{
vars: 'local',
args: 'after-used',
varsIgnorePattern: 'ignored.+',
},
],
/**
* Stylelistic Issues
* (http://eslint.org/docs/rules/#stylistic-issues)
*/
// Enforce 4-space indents, except for switch cases
// http://eslint.org/docs/rules/indent
'indent': [2, 4, { SwitchCase: 1, VariableDeclarator: 1 }],
// Specify the maximum length of a code line to be 100
// http://eslint.org/docs/rules/max-len
'max-len': [
2,
{
code: 105, // Use 105 to give some leeway for *just* slightly longer lines when convienient
ignorePattern: '^(import|export) .* from .*$',
ignoreComments: false,
ignoreTrailingComments: true,
ignoreUrls: true,
},
],
// Require capitalization when using `new`, but don't require capitalized functions to be called
// with new
// http://eslint.org/docs/rules/new-cap
'new-cap': [2, { newIsCap: true, capIsNew: false }],
// Allow the continue statement
// http://eslint.org/docs/rules/no-continue
'no-continue': [0],
// Disallow un-paren'd mixes of different operators if they're not of the same precendence
// http://eslint.org/docs/rules/no-mixed-operators
'no-mixed-operators': [
2,
{
groups: [
['+', '-', '*', '/', '%', '**'],
['&', '|', '^', '~', '<<', '>>', '>>>'],
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
['&&', '||'],
['in', 'instanceof'],
],
allowSamePrecedence: true,
},
],
// Allow use of unary increment/decrement operators
// http://eslint.org/docs/rules/no-plusplus
'no-plusplus': [0],
// Always allow dangling underscores
// http://eslint.org/docs/rules/no-underscore-dangle
'no-underscore-dangle': [0],
// Require unix-style line breaks
// http://eslint.org/docs/rules/linebreak-style
'linebreak-style': [2, 'unix'],
// Require operators to always be at the end of a line, except for the ternary operator
// http://eslint.org/docs/rules/operator-linebreak
'operator-linebreak': [
2,
'after',
{ overrides: { '?': 'ignore', ':': 'ignore' } },
],
// Require properties to be consistently quoted. Force numbers to be quoted, as they can have
// weird behaviour during the coercion into a string)
// http://eslint.org/docs/rules/quote-props
'quote-props': [
2,
'consistent',
{ keywords: false, unnecessary: true, numbers: true },
],
// Require spaces before parens for anonymous function declarations
// http://eslint.org/docs/rules/space-before-function-paren
'space-before-function-paren': [2, { anonymous: 'always', named: 'never' }],
// Require a space immediately following the // or /* in a comment for most comments
// http://eslint.org/docs/rules/spaced-comment
'spaced-comment': [
2,
'always',
{
line: {
exceptions: ['-', '+'],
},
block: {
exceptions: ['*'],
},
},
],
// We don't like semicolons so kill them
// http://eslint.org/docs/rules/semi
'semi': [2, 'never'],
/**
* Import rules
* https://github.com/benmosher/eslint-plugin-import#rules
*/
// Ensure named imports coupled with named exports
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
'import/named': 2,
// Ensure default import coupled with default export
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
'import/default': 2,
// Disallow namespace (wildcard) imports
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
'import/no-namespace': 2,
// Enforce imports to not specify a trailing .js extension
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
'import/extensions': [2, { js: 'never' }],
// Enforce module import order: builtin -> external -> internal
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
'import/order': [
2,
{
groups: [
'builtin',
'external',
['internal', 'parent', 'sibling', 'index'],
],
},
],
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }],
/**
* ES6-specific Issues
* (http://eslint.org/docs/rules/#ecmascript-6)
*/
'arrow-body-style': [0],
'arrow-parens': [0],
'arrow-spacing': [0],
'constructor-super': [0],
'generator-star-spacing': [0],
'no-class-assign': [0],
'no-confusing-arrow': [0],
'no-const-assign': [0],
'no-dupe-class-members': [0],
'no-duplicate-imports': [0],
'no-new-symbol': [0],
'no-restricted-imports': [0],
'no-this-before-super': [0],
'no-useless-computed-key': [0],
'no-useless-constructor': [0],
'no-useless-rename': [0],
'no-var': [0],
'object-shorthand': [0],
'prefer-arrow-callback': [0],
'prefer-const': [0],
'prefer-reflect': [0],
'prefer-rest-params': [0],
'prefer-spread': [0],
'prefer-template': [0],
'require-yield': [0],
'rest-spread-spacing': [0],
'sort-imports': [0],
'template-curly-spacing': [0],
'yield-star-spacing': [0],
},
}

View File

@ -1,3 +0,0 @@
{
"extends": "ascribe"
}

68
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,68 @@
name: CI
on:
push:
branches:
- master
paths-ignore:
- README.md
- API.md
- docs/*.rst
pull_request:
branches:
- master
types:
- ready_for_review
- opened
- reopened
- synchronize
paths-ignore:
- README.md
- API.md
- docs/*.rst
jobs:
test:
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'push' || !github.event.pull_request.draft
timeout-minutes: 10
steps:
- name: Checkout the commit
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Cache dependencies
id: cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Run BigChainDB node
run: |
echo Building and starting up docker containers
docker-compose -f ./docker-compose.yml up -d
- name: Install dependencies
env:
HUSKY_SKIP_INSTALL: 'true'
run: npm install
- name: Lint
run: npm run lint
- name: Build
run: npm run build
# ensure BCDB node is up and running
- run: sleep 20
- name: Test
run: npm run test

11
.gitignore vendored
View File

@ -8,10 +8,19 @@
*.sublime-project
*.sublime-workspace
*.sublime-workspace
.DS_Store
.vscode
.env
.genv
node_modules
dist
package-lock.json
coverage
coverage.lcov
.nyc_output
yarn.lock
package-lock.json
docs/build/
docs/_build/
docs/build/

1
.husky/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_

View File

@ -0,0 +1,24 @@
*.seed
*.log
*.dat
*.out
*.pid
*.gz
.idea
*.sublime-project
*.sublime-workspace
*.sublime-workspace
.DS_Store
.vscode
.env
.genv
node_modules
package-lock.json
coverage
coverage.lcov
.nyc_output
yarn.lock
docs/build/

37
.travis.yml Normal file
View File

@ -0,0 +1,37 @@
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
sudo: required
services:
- docker
language: node_js
node_js:
- 10
- 12
- 14
cache:
directories:
- node_modules
env:
global:
- DOCKER_COMPOSE_VERSION=1.28.5
before_install:
- .ci/travis-before-install.sh
install:
- .ci/travis-install.sh
before_script:
- .ci/travis-before-script.sh
script: npm test
notifications:
email: false

565
API.md
View File

@ -2,217 +2,540 @@
### Table of Contents
- [Ed25519Keypair](#ed25519keypair)
- [makeEd25519Condition](#makeed25519condition)
- [makeSha256Condition](#makesha256condition)
- [makeThresholdCondition](#makethresholdcondition)
- [makeCreateTransaction](#makecreatetransaction)
- [makeOutput](#makeoutput)
- [makeTransferTransaction](#maketransfertransaction)
- [serializeTransactionIntoCanonicalString](#serializetransactionintocanonicalstring)
- [signTransaction](#signtransaction)
- [ccJsonLoad](#ccjsonload)
- [ccJsonify](#ccjsonify)
- [getBlock](#getblock)
- [getStatus](#getstatus)
- [getTransaction](#gettransaction)
- [listBlocks](#listblocks)
- [listOutputs](#listoutputs)
- [listTransactions](#listtransactions)
- [listVotes](#listvotes)
- [pollStatusAndFetchTransaction](#pollstatusandfetchtransaction)
- [postTransaction](#posttransaction)
- [Ed25519Keypair][1]
- [Parameters][2]
- [Properties][3]
- [Connection][4]
- [Parameters][5]
- [getBlock][6]
- [Parameters][7]
- [getTransaction][8]
- [Parameters][9]
- [listBlocks][10]
- [Parameters][11]
- [listOutputs][12]
- [Parameters][13]
- [listTransactions][14]
- [Parameters][15]
- [postTransaction][16]
- [Parameters][17]
- [postTransactionSync][18]
- [Parameters][19]
- [postTransactionAsync][20]
- [Parameters][21]
- [postTransactionCommit][22]
- [Parameters][23]
- [searchAssets][24]
- [Parameters][25]
- [searchMetadata][26]
- [Parameters][27]
- [Transaction][28]
- [serializeTransactionIntoCanonicalString][29]
- [Parameters][30]
- [makeCreateTransaction][31]
- [Parameters][32]
- [makeEd25519Condition][33]
- [Parameters][34]
- [makeOutput][35]
- [Parameters][36]
- [makeSha256Condition][37]
- [Parameters][38]
- [makeThresholdCondition][39]
- [Parameters][40]
- [makeTransferTransaction][41]
- [Parameters][42]
- [signTransaction][43]
- [Parameters][44]
- [delegateSignTransaction][45]
- [Parameters][46]
- [delegateSignTransactionAsync][47]
- [Parameters][48]
- [ccJsonLoad][49]
- [Parameters][50]
- [ccJsonify][51]
- [Parameters][52]
## Ed25519Keypair
**Parameters**
[src/Ed25519Keypair.js:16-21][53]
- `secret` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** A seed that will be used as a key derivation function
Type: [Object][54]
**Properties**
### Parameters
- `publicKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `privateKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `seed` **[Buffer][55]?** A seed that will be used as a key derivation function
## makeEd25519Condition
### Properties
**Parameters**
- `publicKey` **[string][56]**
- `privateKey` **[string][56]**
- `publicKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** base58 encoded Ed25519 public key for the recipient of the Transaction
- `json` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
## Connection
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Ed25519 Condition (that will need to wrapped in an Output)
[src/connection.js:21-199][57]
## makeSha256Condition
### Parameters
**Parameters**
- `nodes`
- `headers` **[Object][54]** Common headers for every request (optional, default `{}`)
- `timeout` **float** Optional timeout in secs (optional, default `DEFAULT_TIMEOUT`)
- `preimage` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Preimage to be hashed and wrapped in a crypto-condition
- `json` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
### getBlock
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Preimage-Sha256 Condition (that will need to wrapped in an Output)
[src/connection.js:79-85][58]
## makeThresholdCondition
#### Parameters
**Parameters**
- `blockHeight`
- `threshold` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `subconditions` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** (optional, default `[]`)
- `json` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
### getTransaction
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Sha256 Threshold Condition (that will need to wrapped in an Output)
[src/connection.js:90-96][59]
## makeCreateTransaction
#### Parameters
**Parameters**
- `transactionId`
- `asset` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Created asset's data
- `metadata` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Metadata for the Transaction
- `outputs` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** Array of Output objects to add to the Transaction.
### listBlocks
[src/connection.js:102-108][60]
#### Parameters
- `transactionId`
- `status`
### listOutputs
[src/connection.js:114-126][61]
#### Parameters
- `publicKey`
- `spent`
### listTransactions
[src/connection.js:132-139][62]
#### Parameters
- `assetId`
- `operation`
### postTransaction
[src/connection.js:144-146][63]
#### Parameters
- `transaction`
### postTransactionSync
[src/connection.js:151-156][64]
#### Parameters
- `transaction`
### postTransactionAsync
[src/connection.js:161-166][65]
#### Parameters
- `transaction`
### postTransactionCommit
[src/connection.js:171-176][66]
#### Parameters
- `transaction`
### searchAssets
[src/connection.js:181-187][67]
#### Parameters
- `search`
### searchMetadata
[src/connection.js:192-198][68]
#### Parameters
- `search`
## Transaction
[src/transaction.js:16-288][69]
Construct Transactions
### serializeTransactionIntoCanonicalString
[src/transaction.js:22-29][70]
Canonically serializes a transaction into a string by sorting the keys
#### Parameters
- `transaction`
- `null` **[Object][54]** (transaction)
Returns **[string][56]** a canonically serialized Transaction
### makeCreateTransaction
[src/transaction.js:80-87][71]
Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
the `issuers`.
#### Parameters
- `asset` **[Object][54]** Created asset's data
- `metadata` **[Object][54]** Metadata for the Transaction
- `outputs` **[Array][72]&lt;[Object][54]>** Array of Output objects to add to the Transaction.
Think of these as the recipients of the asset after the transaction.
For `CREATE` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the issuers' public
keys (so that the issuers are the recipients of the created asset).
- `issuers` **...[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Public key of one or more issuers to the asset being created by this
- `issuers` **...[Array][72]&lt;[string][56]>** Public key of one or more issuers to the asset being created by this
Transaction.
Note: Each of the private keys corresponding to the given public
keys MUST be used later (and in the same order) when signing the
Transaction (`signTransaction()`).
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Unsigned transaction -- make sure to call signTransaction() on it before
Returns **[Object][54]** Unsigned transaction -- make sure to call signTransaction() on it before
sending it off!
## makeOutput
### makeEd25519Condition
**Parameters**
[src/transaction.js:96-101][73]
- `condition` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
- `amount` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Amount of the output (optional, default `1`)
Create an Ed25519 Cryptocondition from an Ed25519 public key
to put into an Output of a Transaction
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** An Output usable in a Transaction
#### Parameters
## makeTransferTransaction
- `publicKey` **[string][56]** base58 encoded Ed25519 public key for the recipient of the Transaction
- `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
**Parameters**
Returns **[Object][54]** Ed25519 Condition (that will need to wrapped in an Output)
- `unspentTransaction` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Previous Transaction you have control over (i.e. can fulfill
its Output Condition)
- `metadata` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Metadata for the Transaction
- `outputs` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** Array of Output objects to add to the Transaction.
### makeOutput
[src/transaction.js:111-131][75]
Create an Output from a Condition.
Note: Assumes the given Condition was generated from a
single public key (e.g. a Ed25519 Condition)
#### Parameters
- `condition` **[Object][54]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
- `amount` **[string][56]** Amount of the output (optional, default `'1'`)
Returns **[Object][54]** An Output usable in a Transaction
### makeSha256Condition
[src/transaction.js:139-143][76]
Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
#### Parameters
- `preimage` **[string][56]** Preimage to be hashed and wrapped in a crypto-condition
- `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][54]** Preimage-Sha256 Condition (that will need to wrapped in an Output)
### makeThresholdCondition
[src/transaction.js:152-162][77]
Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
#### Parameters
- `threshold` **[number][78]**
- `subconditions` **[Array][72]** (optional, default `[]`)
- `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][54]** Sha256 Threshold Condition (that will need to wrapped in an Output)
### makeTransferTransaction
[src/transaction.js:185-206][79]
Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
the `fulfilledOutputs` of `unspentTransaction`.
#### Parameters
- `unspentOutputs`
- `outputs` **[Array][72]&lt;[Object][54]>** Array of Output objects to add to the Transaction.
Think of these as the recipients of the asset after the transaction.
For `TRANSFER` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the public keys of
the recipients.
- `fulfilledOutputs` **...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Indices of the Outputs in `unspentTransaction` that this
- `metadata` **[Object][54]** Metadata for the Transaction
- `unspentTransaction` **[Object][54]** Previous Transaction you have control over (i.e. can fulfill
its Output Condition)
- `OutputIndices` **...[number][78]** Indices of the Outputs in `unspentTransaction` that this
Transaction fulfills.
Note that the public keys listed in the fulfilled Outputs
must be used (and in the same order) to sign the Transaction
Note that listed public keys listed must be used (and in
the same order) to sign the Transaction
(`signTransaction()`).
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Unsigned transaction -- make sure to call signTransaction() on it before
Returns **[Object][54]** Unsigned transaction -- make sure to call signTransaction() on it before
sending it off!
## serializeTransactionIntoCanonicalString
### signTransaction
**Parameters**
[src/transaction.js:219-243][80]
- `transaction`
- `null` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** (transaction)
Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
that's been signed.
Note: Only generates Ed25519 Fulfillments. Thresholds and other types of Fulfillments are left as
an exercise for the user.
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** a canonically serialized Transaction
#### Parameters
## signTransaction
**Parameters**
- `transaction` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Private keys associated with the issuers of the `transaction`.
- `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string][56]** Private keys associated with the issuers of the `transaction`.
Looped through to iteratively sign any Input Fulfillments found in
the `transaction`.
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The signed version of `transaction`.
Returns **[Object][54]** The signed version of `transaction`.
### delegateSignTransaction
[src/transaction.js:252-265][81]
Delegate signing of the given `transaction` returning a new copy of `transaction`
that's been signed.
#### Parameters
- `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
- `signFn` **[Function][82]** Function signing the transaction, expected to return the fulfillment.
Returns **[Object][54]** The signed version of `transaction`.
### delegateSignTransactionAsync
[src/transaction.js:274-287][83]
Delegate signing of the given `transaction` returning a new copy of `transaction`
that's been signed.
#### Parameters
- `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
- `signFn` **[Function][82]** Function signing the transaction, expected to resolve the fulfillment.
Returns **[Promise][84]&lt;[Object][54]>** The signed version of `transaction`.
## ccJsonLoad
**Parameters**
[src/utils/ccJsonLoad.js:13-44][85]
- `conditionJson` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
### Parameters
- `conditionJson` **[Object][54]**
Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)
## ccJsonify
**Parameters**
[src/utils/ccJsonify.js:12-65][86]
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for the recipient of the Transaction
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Ed25519 Condition (that will need to wrapped in an Output)
### Parameters
## getBlock
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
**Parameters**
Returns **[Object][54]** Ed25519 Condition (that will need to wrapped in an Output)
- `blockId`
[1]: #ed25519keypair
## getStatus
[2]: #parameters
**Parameters**
[3]: #properties
- `tx_id`
[4]: #connection
## getTransaction
[5]: #parameters-1
**Parameters**
[6]: #getblock
- `txId`
[7]: #parameters-2
## listBlocks
[8]: #gettransaction
**Parameters**
[9]: #parameters-3
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.tx_id`
- `$0.status`
- `tx_id`
- `status`
[10]: #listblocks
## listOutputs
[11]: #parameters-4
**Parameters**
[12]: #listoutputs
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.public_key`
- `$0.unspent`
- `onlyJsonResponse`
- `public_key`
- `unspent`
[13]: #parameters-5
## listTransactions
[14]: #listtransactions
**Parameters**
[15]: #parameters-6
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.asset_id`
- `$0.operation`
- `asset_id`
- `operation`
[16]: #posttransaction
## listVotes
[17]: #parameters-7
**Parameters**
[18]: #posttransactionsync
- `block_id`
[19]: #parameters-8
## pollStatusAndFetchTransaction
[20]: #posttransactionasync
**Parameters**
[21]: #parameters-9
- `tx_id`
[22]: #posttransactioncommit
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
[23]: #parameters-10
## postTransaction
[24]: #searchassets
**Parameters**
[25]: #parameters-11
- `transaction`
[26]: #searchmetadata
[27]: #parameters-12
[28]: #transaction
[29]: #serializetransactionintocanonicalstring
[30]: #parameters-13
[31]: #makecreatetransaction
[32]: #parameters-14
[33]: #makeed25519condition
[34]: #parameters-15
[35]: #makeoutput
[36]: #parameters-16
[37]: #makesha256condition
[38]: #parameters-17
[39]: #makethresholdcondition
[40]: #parameters-18
[41]: #maketransfertransaction
[42]: #parameters-19
[43]: #signtransaction
[44]: #parameters-20
[45]: #delegatesigntransaction
[46]: #parameters-21
[47]: #delegatesigntransactionasync
[48]: #parameters-22
[49]: #ccjsonload
[50]: #parameters-23
[51]: #ccjsonify
[52]: #parameters-24
[53]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/Ed25519Keypair.js#L16-L21 "Source code on GitHub"
[54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[55]: https://nodejs.org/api/buffer.html
[56]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[57]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L21-L199 "Source code on GitHub"
[58]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L79-L85 "Source code on GitHub"
[59]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L90-L96 "Source code on GitHub"
[60]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L102-L108 "Source code on GitHub"
[61]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L114-L126 "Source code on GitHub"
[62]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L132-L139 "Source code on GitHub"
[63]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L144-L146 "Source code on GitHub"
[64]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L151-L156 "Source code on GitHub"
[65]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L161-L166 "Source code on GitHub"
[66]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L171-L176 "Source code on GitHub"
[67]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L181-L187 "Source code on GitHub"
[68]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L192-L198 "Source code on GitHub"
[69]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L16-L288 "Source code on GitHub"
[70]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L22-L29 "Source code on GitHub"
[71]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L80-L87 "Source code on GitHub"
[72]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[73]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L96-L101 "Source code on GitHub"
[74]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[75]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L111-L131 "Source code on GitHub"
[76]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L139-L143 "Source code on GitHub"
[77]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L152-L162 "Source code on GitHub"
[78]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[79]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L185-L206 "Source code on GitHub"
[80]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L219-L243 "Source code on GitHub"
[81]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L252-L265 "Source code on GitHub"
[82]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[83]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L274-L287 "Source code on GitHub"
[84]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[85]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/utils/ccJsonLoad.js#L13-L44 "Source code on GitHub"
[86]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/utils/ccJsonify.js#L12-L65 "Source code on GitHub"

7
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,7 @@
<!---
Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
--->
See [https://github.com/bigchaindb/bigchaindb/blob/master/CODE_OF_CONDUCT.md](https://github.com/bigchaindb/bigchaindb/blob/master/CODE_OF_CONDUCT.md)

View File

@ -1,3 +1,8 @@
.. Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
.. highlight:: shell
============

0
LICENSE Executable file → Normal file
View File

4
LICENSE-docs Normal file
View File

@ -0,0 +1,4 @@
The official BigchainDB documentation, _except for the short code snippets
embedded within it_, is licensed under a Creative Commons Attribution-
ShareAlike 4.0 International license, the full text of which can be found
at http://creativecommons.org/licenses/by-sa/4.0/legalcode

207
README.md
View File

@ -1,80 +1,181 @@
<!---
Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
--->
# [![js-bigchaindb-driver](media/repo-banner@2x.png)](https://www.bigchaindb.com)
> Official JavaScript driver for [BigchainDB](https://github.com/bigchaindb/bigchaindb) with some naive helpers to get you on your way making transactions in Node.js and the browser.
> Official JavaScript driver for [BigchainDB](https://github.com/bigchaindb/bigchaindb) to create transactions in Node.js and the browser.
[![Join the chat at https://gitter.im/bigchaindb/js-bigchaindb-driver](https://badges.gitter.im/bigchaindb/js-bigchaindb-driver.svg)](https://gitter.im/bigchaindb/js-bigchaindb-driver?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![npm](https://img.shields.io/npm/v/bigchaindb-driver.svg)](https://www.npmjs.com/package/bigchaindb-driver)
[![codecov](https://codecov.io/gh/bigchaindb/js-bigchaindb-driver/branch/master/graph/badge.svg)](https://codecov.io/gh/bigchaindb/js-bigchaindb-driver)
[![js ascribe](https://img.shields.io/badge/js-ascribe-39BA91.svg)](https://github.com/ascribe/javascript)
[![Build Status](https://travis-ci.org/bigchaindb/js-bigchaindb-driver.svg?branch=master)](https://travis-ci.org/bigchaindb/js-bigchaindb-driver)
[![Build Status](https://travis-ci.com/bigchaindb/js-bigchaindb-driver.svg?branch=master)](https://travis-ci.com/bigchaindb/js-bigchaindb-driver)
[![Greenkeeper badge](https://badges.greenkeeper.io/bigchaindb/js-bigchaindb-driver.svg)](https://greenkeeper.io/)
- [Main Documentation](https://docs.bigchaindb.com/projects/js-driver/en/latest/usage.html)
- [Driver API reference](API.md)
## Compatibility
| BigchainDB Server | BigchainDB JavaScript Driver |
| ----------------- |------------------------------|
| `0.10` | `0.1.0` |
| `0.10` | `0.1.x` |
| `1.0.0` | `0.3.x` |
| `1.3.x` | `3.x.x` |
| `>= 2.0.0` | `4.x.x` |
## Breaking changes
## Contents
- **Version 4.0** of BigchainDB JavaScript Driver makes the driver compatible with BigchainDB 2.0. There are new functions for sending off transactions along with other changes. Check [older versions](https://docs.bigchaindb.com/projects/js-driver/en/latest/readme.html#features)
- **Version 3.2** of BigchainDB JavaScript Driver introduces a new way of creating transfer transactions. Check [older versions](https://docs.bigchaindb.com/projects/js-driver/en/latest/readme.html#features)
* [Installation](#installation)
* [Example: Create a transaction](#example-create-a-transaction)
* [Documentation](#bigchaindb-documentation)
* [Authors](#authors)
* [License](#license)
## Table of Contents
## Installation
- [Installation and Usage](#installation-and-usage)
- [Example: Create a transaction](#example-create-a-transaction)
- [Browser usage](#browser-usage)
- [BigchainDB Documentation](#bigchaindb-documentation)
- [Speed Optimizations](#speed-optimizations)
- [Development](#development)
- [Release Process](#release-process)
- [Authors](#authors)
- [Licenses](#licenses)
---
## Installation and Usage
```bash
npm install bigchaindb-driver
```
```js
const driver = require('bigchaindb-driver')
// or ES6+
import driver from 'bigchaindb-driver'
```
### Example: Create a transaction
```js
import * as driver from 'bigchaindb-driver'
const driver = require('bigchaindb-driver')
const base58 = require('bs58');
const crypto = require('crypto');
const { Ed25519Sha256 } = require('crypto-conditions');
// BigchainDB server instance or IPDB (e.g. https://test.ipdb.io/api/v1/)
// BigchainDB server instance (e.g. https://example.com/api/v1/)
const API_PATH = 'http://localhost:9984/api/v1/'
// Create a new user with a public-private key pair
// (or a whole bunch of them, nobody's counting)
// Create a new keypair.
const alice = new driver.Ed25519Keypair()
// Construct a transaction payload
// `driver.Transaction.makeCreateTransaction()`: create a new asset
// `driver.Transaction.makeTransferTransaction()`: transfer an existing asset
const tx = driver.Transaction.makeCreateTransaction(
{ assetMessage: 'My very own asset...' },
{ metaDataMessage: 'wrapped in a transaction' },
// Define the asset to store, in this example it is the current temperature
// (in Celsius) for the city of Berlin.
{ city: 'Berlin, DE', temperature: 22, datetime: new Date().toString() },
// Metadata contains information about the transaction itself
// (can be `null` if not needed)
{ what: 'My first BigchainDB transaction' },
// A transaction needs an output
// `driver.Transaction.makeOutput()`: requires a crypto-condition
// `driver.Transaction.makeEd25519Condition()`: simple public key output
[ driver.Transaction.makeOutput(
driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
// 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
// cause, you know... cryptography and ¯\_(ツ)_/¯
// Sign/fulfill the transaction with private keys
// Sign the transaction with private keys
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
// Send the transaction off to BigchainDB
let conn = new driver.Connection(API_PATH, { 'Content-Type': 'application/json' })
// Or use delegateSignTransaction to provide your own signature function
function signTransaction() {
// get privateKey from somewhere
const privateKeyBuffer = Buffer.from(base58.decode(alice.privateKey))
return function sign(serializedTransaction, input, index) {
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
.concat(input.fulfills.transaction_id)
.concat(input.fulfills.output_index) : serializedTransaction
const transactionHash = crypto.createHash('sha3-256').update(transactionUniqueFulfillment).digest()
const ed25519Fulfillment = new Ed25519Sha256();
ed25519Fulfillment.sign(transactionHash, privateKeyBuffer);
return ed25519Fulfillment.serializeUri();
};
}
const txSigned = driver.Transaction.delegateSignTransaction(tx, signTransaction())
conn.postTransaction(txSigned)
.then(() => conn.getStatus(txSigned.id))
.then((res) => console.log('Transaction status:', res.status))
// Send the transaction off to BigchainDB
const conn = new driver.Connection(API_PATH)
conn.postTransactionCommit(txSigned)
.then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.'))
```
### Browser usage
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BigchainDB boilerplate</title>
<!-- Adjust version to your needs -->
<script src="https://unpkg.com/bigchaindb-driver@4.2.0/dist/browser/bigchaindb-driver.window.min.js"></script>
<script>
// BigchainDB server instance (e.g. https://example.com/api/v1/)
const API_PATH = 'http://localhost:9984/api/v1/'
// Create a new keypair.
const alice = new BigchainDB.Ed25519Keypair()
// Construct a transaction payload
const tx = BigchainDB.Transaction.makeCreateTransaction(
// Define the asset to store, in this example it is the current temperature
// (in Celsius) for the city of Berlin.
{ city: 'Berlin, DE', temperature: 22, datetime: new Date().toString() },
// Metadata contains information about the transaction itself
// (can be `null` if not needed)
{ what: 'My first BigchainDB transaction' },
// A transaction needs an output
[ BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(tx, alice.privateKey)
// Send the transaction off to BigchainDB
let conn = new BigchainDB.Connection(API_PATH)
conn.postTransactionCommit(txSigned)
.then(res => {
const elem = document.getElementById('lastTransaction')
elem.href = API_PATH + 'transactions/' + txSigned.id
elem.innerText = txSigned.id
console.log('Transaction', txSigned.id, 'accepted')
})
// Check console for the transaction's status
</script>
</head>
<body id="home">
<h1>Hello BigchainDB</h1>
<p>Your transaction id is: <a id="lastTransaction" target="_blank"><em>processing</em></a></p>
</body>
</html>
```
## BigchainDB Documentation
- [The Hitchhiker's Guide to BigchainDB](https://www.bigchaindb.com/developers/guide/)
- [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html)
- [The Transaction Model](https://docs.bigchaindb.com/projects/server/en/latest/data-models/transaction-model.html?highlight=crypto%20conditions)
- [Inputs and Outputs](https://docs.bigchaindb.com/projects/server/en/latest/data-models/inputs-outputs.html)
@ -88,26 +189,32 @@ This implementation plays "safe" by using JS-native (or downgradable) libraries
* [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)
## Development
```js
git clone git@github.com:bigchaindb/js-bigchaindb-driver.git
cd js-bigchaindb-driver/
npm i
npm run dev
```
After updating source files in `src/`, make sure to update the API documentation. The following command will scan all source files and create the Markdown output into `./API.md`:
```bash
npm run doc
```
## Release Process
See the file named [RELEASE_PROCESS.md](RELEASE_PROCESS.md).
## Authors
* inspired by [`js-bigchaindb-quickstart`](https://github.com/sohkai/js-bigchaindb-quickstart) of @sohkhai [thanks]
* BigchainDB <dev@bigchaindb.com>
* BigchainDB <contact@ipdb.global>
* BigchainDB contributors
## License
## Licenses
```
Copyright 2017 BigchainDB GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
See [LICENSE](LICENSE) and [LICENSE-docs](LICENSE-docs).

91
RELEASE_PROCESS.md Normal file
View File

@ -0,0 +1,91 @@
<!---
Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
--->
# Our Release Process
## Notes
BigchainDB follows
[the Python form of Semantic Versioning](https://packaging.python.org/tutorials/distributing-packages/#choosing-a-versioning-scheme)
(i.e. MAJOR.MINOR.PATCH),
which is almost identical
to [regular semantic versioning](http://semver.org/), but there's no hyphen, e.g.
- `0.9.0` for a typical final release
- `4.5.2a1` not `4.5.2-a1` for the first Alpha release
- `3.4.5rc2` not `3.4.5-rc2` for Release Candidate 2
**Note:** For Git tags (which are used to identify releases on GitHub), we append a `v` in front.
We follow [BEP-1](https://github.com/bigchaindb/BEPs/tree/master/1), which is our variant of C4, the Collective Code Construction Contract, so a release is just a [tagged commit](https://git-scm.com/book/en/v2/Git-Basics-Tagging) on the `master` branch, i.e. a label for a particular Git commit.
## Steps
1. Make sure you have a recent version of node and npm.
1. `npm install`
1. Update all npm package dependencies, where possible. You might have to freeze some versions. Run all tests locally (`npm run test`) and make sure they pass. Make a pull request (to be merged into the `master` branch) and make sure all tests are passing there (in Travis). Merge the pull request.
1. Make sure your local `master` branch is in sync with GitHub: `git checkout master` and `git pull`
1. Do a test build:
`npm run build`
If that fails, then get it working.
1. We use the [release-it](https://www.npmjs.com/package/release-it) package (from npm) to automate most of the release. Make sure you have a recent version.
1. Login to npm using your npm credentials, so you can publish a new [bigchaindb-driver](https://www.npmjs.com/package/bigchaindb-driver) package there. (The npm account must have permission to do so).
`npm login`
1. release-it needs a Github personal access token so it can interact with GitHub on your behalf. To get one, go to:
[https://github.com/settings/tokens](https://github.com/settings/tokens)
and then make that token available as an environment variable, e.g.
`export GITHUB_TOKEN="f941e0..."`
1. Do the release:
- For a patch release, do `npm run release`
- For a minor release, do `npm run release-minor`
- For a major release, do `npm run release-major`
If your npm account is using two-factor authentication,
you will have to append a one-time password (OTP) like `--npm.otp=123456`.
The above command will automatically do a bunch of things:
- bump the project version in `package.json`, then git commit and git push it.
- create a new Git tag of the form `v{verson}`, e.g. `v1.2.3`
- create a new [GitHub release](https://github.com/bigchaindb/js-bigchaindb-driver/releases).
- publish a new npm release
To see all the arguments passed to `release-it`, search for "release" in [package.json](package.json). The arguments are documented in the [release-it GitHub repo](https://github.com/release-it/release-it).
1. Make sure everything worked as expected.
- Was the version number bumped properly in [package.json](package.json)?
- Was a new Git tag created? See the [list of tags](https://github.com/bigchaindb/js-bigchaindb-driver/tags).
- Was a new GitHub release created? See the [list of releases](https://github.com/bigchaindb/js-bigchaindb-driver/releases).
- Was a new npm package published on npm? [Check on npmjs.com](https://www.npmjs.com/package/bigchaindb-driver).
1. You can edit the description of the GitHub release to add or remove details.
If the docs were updated since the last release, [login to readthedocs.org](https://readthedocs.org/accounts/login/) and go to the **BigchainDB JavaScript Driver** project, then:
1. Click on "Builds", select "latest" from the drop-down menu, then click the "Build Version:" button.
1. Wait for the build of "latest" to finish. This can take a few minutes.
1. Go to Admin --> Advanced Settings
and make sure that "Default branch:" (i.e. what "latest" points to)
is set to the new release's tag, e.g. `v0.9.1`.
(It won't be an option if you didn't wait for the build of "latest" to finish.)
Then scroll to the bottom and click "Save".
1. Go to Admin --> Versions
and under **Choose Active Versions**, do these things:
1. Make sure that the new version's tag is "Active" and "Public"
1. Make sure the **stable** branch is _not_ active.
1. Scroll to the bottom of the page and click "Save".
Congratulations, you have released a new version of the BigchainDB JavaScript Driver!

12
compose/Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM python:3.6
RUN apt-get update && apt-get install -y vim
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN pip install --upgrade pip ipdb ipython
COPY . /usr/src/app/
RUN pip install git+https://github.com/bigchaindb/bigchaindb.git

View File

@ -0,0 +1,17 @@
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
proxy_app = "tcp://bigchaindb:46658"
moniker = "anonymous"
fast_sync = true
db_backend = "leveldb"
log_level = "state:debug,*:error"
[consensus]
create_empty_blocks = false
[rpc]
laddr = "tcp://0.0.0.0:46657"
[p2p]
laddr = "tcp://0.0.0.0:46656"

43
docker-compose.yml Normal file
View File

@ -0,0 +1,43 @@
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
version: '2.1'
services:
mongodb:
image: mongo:3.6
ports:
- "27017"
command: mongod
bigchaindb:
depends_on:
- mongodb
- tendermint
image: bigchaindb/bigchaindb:master
environment:
BIGCHAINDB_DATABASE_HOST: mongodb
BIGCHAINDB_DATABASE_PORT: 27017
BIGCHAINDB_SERVER_BIND: 0.0.0.0:9984
BIGCHAINDB_WSSERVER_HOST: 0.0.0.0
BIGCHAINDB_TENDERMINT_HOST: tendermint
BIGCHAINDB_TENDERMINT_PORT: 26657
ports:
- "9984:9984"
- "9985:9985"
- "26658"
healthcheck:
test: ["CMD", "bash", "-c", "curl http://bigchaindb:9984 && curl http://tendermint:26657/abci_query"]
interval: 3s
timeout: 5s
retries: 3
command: -l DEBUG start
tendermint:
image: tendermint/tendermint:v0.31.5
# volumes:
# - ./tmdata:/tendermint
entrypoint: ''
ports:
- "26656"
- "26657"
command: sh -c "tendermint init && tendermint node --consensus.create_empty_blocks=false --proxy_app=tcp://bigchaindb:26658"

32
docs/Makefile Normal file
View File

@ -0,0 +1,32 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = BigchainDBJavascriptDriver
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
.PHONY: clean
clean:
rm -rf $(BUILDDIR)/*
@echo
@echo "Removed $(BUILDDIR)/html."
.PHONY: html
html:
$(SPHINXBUILD) -b html $(SOURCEDIR) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

8
docs/README.md Normal file
View File

@ -0,0 +1,8 @@
<!---
Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
--->
# BigchainDBJavaScriptDriverDocs
BigchainDB JavaScript Driver Documentation with Sphinx

36
docs/make.bat Normal file
View File

@ -0,0 +1,36 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=python -msphinx
)
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXPROJ=BigchainDBJavascriptDriver
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The Sphinx module was not found. Make sure you have Sphinx installed,
echo.then set the SPHINXBUILD environment variable to point to the full
echo.path of the 'sphinx-build' executable. Alternatively you may add the
echo.Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
:end
popd

3
docs/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
Sphinx~=1.0
recommonmark>=0.4.0
sphinx-rtd-theme>=0.2.4

BIN
docs/source/.conf.py.swp Normal file

Binary file not shown.

87
docs/source/advanced.rst Normal file
View File

@ -0,0 +1,87 @@
.. Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
=================
Advanced Examples
=================
Crypto Conditions
-----------------
Let's start with a basic use case example. Alice bought a bicycle for €240.
She will use the bike for a year and will give it to her daughter afterwards.
First, we create an asset registering the bicycle:
.. code-block:: js
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
{'asset': 'bicycle'},
{'purchase_price': '€240'},
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
const txCreateAliceSimpleSigned = driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
After a year, she decides it's time to transfer the bicycle to her daughter Carly.
However, Alice wants to maintain the right over the bike so she can possibly sell it. If she would transfer the bicycle to Carly, she won't be able to do this.
So, Alice needs a crypto conditions that defines that she or her daughter can sign the ``TRANSFER`` transaction to a possible buyer.
We need to define a threshold as well. This defines how many persons have to sign the transaction to ``TRANSFER`` it.
In this case, we define two subconditions with the public keys from Alice and Carly. Next, we set the threshold to **one**.
This means that just one of the subconditions has to sign the transaction to transfer it.
This can be the mother Alice, or Carly herself.
.. code-block:: js
// Create condition for Alice and Carly
let subConditionFrom = driver.Transaction.makeEd25519Condition(alice.publicKey, false)
let subConditionTo = driver.Transaction.makeEd25519Condition(carly.publicKey, false)
// Create condition object with threshold and subconditions
let condition = driver.Transaction.makeThresholdCondition(1, [subConditionFrom, subConditionTo])
// Generate output with condition added
let output = driver.Transaction.makeOutput(condition)
// Add Carly to the output.public_keys field so she is the owner
output.public_keys = [carly.publicKey]
let transaction = driver.Transaction.makeTransferTransaction(
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[output],
{'meta': 'Transfer to new user with conditions'}
);
// Add alice as previous owner
transaction.inputs[0].owners_before = [alice.publicKey]
// Because the addition of crypto conditions, the id for the transaction has to be regenerated
delete transaction.id
transaction.id = sha3.sha3_256
.create()
.update(driver.Transaction.serializeTransactionIntoCanonicalString(transaction))
.hex()
// Alice has to sign this transfer because she is still the owner of the created asset
let signedCryptoConditionTx = driver.Transaction.signTransaction(transaction, alice.privateKey)
As you can see, we need to generate a new transactionId because we have added crypto conditions.
We do this with the js-sha3 package, you need to install this package through ``npm``:
``npm install --save js-sha3``
Don't forget to import the package in your code:
.. code-block:: js
import * as sha3 from 'js-sha3'
If you would like to see a more complex example, please have a look [here](https://github.com/bigchaindb/project-jannowitz/blob/code-examples/js-examples/crypto-conditions.js)
.. TODO: Document Utils when finished

189
docs/source/conf.py Normal file
View File

@ -0,0 +1,189 @@
#!/usr/bin/env python3
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
#
# BigchainDB Javascript Driver documentation build configuration file, created by
# sphinx-quickstart on Wed Aug 2 15:39:03 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
import datetime
import sphinx_rtd_theme
from recommonmark.parser import CommonMarkParser
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['ntemplates']
source_parsers = {
'.md': CommonMarkParser,
}
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ['.rst', '.md']
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'BigchainDB Javascript Driver'
now = datetime.datetime.now()
copyright = str(now.year) + ', BigchainDB Contributors'
author = 'BigchainDB Contributors'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.0.1'
# The full version, including alpha/beta/rc tags.
release = '0.0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['nstatic']
# Commented out this option because Sphinx can not find the path
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
]
}
# -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'BigchainDBJavascriptDriverdoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'BigchainDBJavascriptDriver.tex', 'BigchainDB Javascript Driver Documentation',
'BigchainDB', 'manual'),
]
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'bigchaindbjavascriptdriver', 'BigchainDB Javascript Driver Documentation',
[author], 1)
]
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'BigchainDBJavascriptDriver', 'BigchainDB Javascript Driver Documentation',
author, 'BigchainDBJavascriptDriver', 'One line description of project.',
'Miscellaneous'),
]

23
docs/source/index.rst Normal file
View File

@ -0,0 +1,23 @@
.. Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
BigchainDB Javascript Driver Documentation
==========================================
.. toctree::
:maxdepth: 2
← Back to All BigchainDB Docs <https://bigchaindb.readthedocs.io/en/latest/index.html>
readme
quickstart
usage
advanced
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -0,0 +1,14 @@
.. Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
=========================
Quickstart / Installation
=========================
Installation with package manager npm:
.. code-block:: bash
$ npm install bigchaindb-driver

120
docs/source/readme.rst Normal file
View File

@ -0,0 +1,120 @@
.. Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
BigchainDB JavaScript Driver
============================
.. image:: https://img.shields.io/npm/v/bigchaindb-driver.svg
:target: https://www.npmjs.com/package/bigchaindb-driver
.. image:: https://codecov.io/gh/bigchaindb/js-bigchaindb-driver/branch/master/graph/badge.svg
:target: https://codecov.io/gh/bigchaindb/js-bigchaindb-driver
.. image:: https://img.shields.io/badge/js-ascribe-39BA91.svg
:target: https://github.com/ascribe/javascript
.. image:: https://travis-ci.com/bigchaindb/js-bigchaindb-driver.svg?branch=master
:target: https://travis-ci.com/bigchaindb/js-bigchaindb-driver
.. image:: https://badges.greenkeeper.io/bigchaindb/js-bigchaindb-driver.svg
:target: https://greenkeeper.io/
Features
--------
* Support for preparing, fulfilling, and sending transactions to a BigchainDB
node.
* Retrieval of transactions by id.
* Getting status of a transaction by id.
Compatibility Matrix
--------------------
+-----------------------+----------------------------------+
| **BigchainDB Server** | **BigchainDB Javascript Driver** |
+=======================+==================================+
| ``0.10`` | ``0.1.x`` |
+-----------------------+----------------------------------+
| ``1.0`` | ``0.3.x`` |
+-----------------------+----------------------------------+
| ``1.3`` | ``3.x.x`` |
+-----------------------+----------------------------------+
| ``2.0`` | ``4.x.x`` |
+-----------------------+----------------------------------+
Older versions
--------------------
**Version 4.x.x**
As part of the changes in the BigchainDB 2.0 server, some endpoints were
modified. In order to be consistent with them, the JS driver does not have
anymore the `pollStatusAndFetchTransaction()` method as there are three
different ways of posting a transaction:
- `commit` using the `postTransaction` or the `postTransactionCommit`: the response will return after the transaction is committed to a block.
- `sync` using the `postTransactionSync`: the response will return after the transaction is validated.
- `async` using the `postTransactionAsync`: the response will return immediately and not wait to see if the transaction is valid.
By default in the docs we will use the `postTransactionCommit` as is way of
being sure that the transaction is validated and commited to a block, so
there will not be any issue if you try to do any other action with the asset immediately.
Note: In order to not create breaking changes, both methods `postTransaction` and `postTransactionCommit` are kept although
they do exactly the same
**Version 3.2.x**
For versions below 3.2, a transfer transaction looked like:
.. code-block:: js
const createTranfer = BigchainDB.Transaction.makeTransferTransaction(
txCreated,
metadata, [BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))],
0
)
const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer,
keypair.privateKey)
In order to upgrade and do it compatible with the new driver version, this
transaction should be now:
.. code-block:: js
const createTranfer = BigchainDB.Transaction.makeTransferTransaction(
[{ tx: txCreated, output_index: 0 }],
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))],
metaData
)
const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer,
keypair.privateKey)
The upgrade allows to create transfer transaction spending outputs that belong
to different transactions. So for instance is now possible to create a transfer
transaction spending two outputs from two different create transactions:
.. code-block:: js
const createTranfer = BigchainDB.Transaction.makeTransferTransaction(
[{ tx: txCreated1, output_index: 0 },
{ tx: txCreated2, output_index: 0}],
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))],
metaData
)
const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer,
keypair.privateKey)

795
docs/source/usage.rst Normal file
View File

@ -0,0 +1,795 @@
.. Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
====================
Basic Usage Examples
====================
For the examples on this page, we assume you've
:doc:`installed the bigchaindb_driver JavaScript package <quickstart>`,
and you have determined the BigchainDB Root URL (issue: move this to general docs)
of the node or cluster you want to connect to.
This example guides you through creating and transferring an asset.
We walk through the code explaining its use, some pieces are left out
because they have no real use (e.g. definition of global variable)
*Full working code* can be found at the bottom of this document.
The following code are just snippets.
Getting Started
---------------
We begin by importing the BigchainDB driver:
.. code-block:: js
const driver = require('bigchaindb-driver')
Next, we define a constant containing the API path.
.. code-block:: js
const API_PATH = 'http://localhost:9984/api/v1/'
Create a Connection with BigchainDB
-----------------------------------
A simple connection with a BigchainDB node can be established like this:
.. code-block:: js
const conn = new driver.Connection(API_PATH)
If the BigchainDB node requires special HTTP request headers
(such as ``app_id`` and ``app_key``),
they can be included like this:
.. code-block:: js
const conn = new driver.Connection(API_PATH, {
app_id: 'app_id_value',
app_key: 'app_key_value'
})
A more complex connection can be created if the BigchainDB network
has several nodes, each with a different API path and different required headers.
The connection strategy will be the one specified in BEP-14_.
.. _BEP-14: https://github.com/bigchaindb/BEPs/tree/master/14#connection-strategy
.. code-block:: js
const conn = new driver.Connection([
API_PATH_1, // the first node does not use custom headers, only common headers
{endpoint: API_PATH_2,
headers: {app_id: 'your_app_id',
app_key: 'your_app_key'}},
{endpoint: API_PATH_3,
headers: {app_id: 'your_app_id',
app_key: 'your_app_key',
extra_header: 'extra value'}},
{endpoint: API_PATH_4,
headers: {app_id: 'your_app_id',
app_key: 'your_app_key',
other_header: 'other value'}},
{endpoint: API_PATH_5,
headers: {custom_auth: 'custom token'}],
{'sender_id': 'ab-12769'} // common header sent to all nodes
)
Cryptographic Identities Generation
-----------------------------------
Alice and Bob are represented by public/private key pairs. The private key is
used to sign transactions, meanwhile the public key is used to verify that a
signed transaction was indeed signed by the one who claims to be the signee.
.. code-block:: js
const alice = new driver.Ed25519Keypair()
const bob = new driver.Ed25519Keypair()
Digital Asset Definition
------------------------
As an example, lets consider the creation and transfer of a digital asset
that represents a bicycle:
.. code-block:: js
const assetdata = {
'bicycle': {
'serial_number': 'abcd1234',
'manufacturer': 'Bicycle Inc.',
}
}
We'll suppose that the bike belongs to Alice, and that it eventually will be
transferred to Bob.
In general, you are free to define any JSON object you which to store for the
``'data'`` property (assetdata).
Metadata Definition (*optional*)
--------------------------------
You can `optionally` add metadata to a transaction. Any JSON object is accepted.
For example, the bicycle will be transferred on earth which is metadata:
.. code-block:: js
const metadata = {'planet': 'earth'}
Asset Creation
--------------
We're now ready to create the digital asset. First, let's make a 'CREATE'
transaction:
.. code-block:: js
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
metadata,
// A transaction needs an output
[ driver.Transaction.makeOutput(
driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
Transaction needs an array of Output objects.
Think of these as the recipients of the asset after the transaction.
For `CREATE` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the issuers' public
keys (so that the issuers are the recipients of the created asset).
``alice.publicKey`` can be considered as the Input for the transaction.
Each input spends/transfers a previous output by satisfying/fulfilling
the crypto-conditions on that output. A CREATE transaction should have
exactly one input. A TRANSFER transaction should have at least one input (i.e. ≥1).
Sign the transaction with private key of Alice to fulfill it:
.. code-block:: js
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
And sent over to a BigchainDB node:
.. code-block:: js
conn.postTransactionCommit(txCreateAliceSimpleSigned)
Notice the transaction ``id``:
.. code-block:: js
txid = txCreateAliceSimpleSigned.id
Asset Transfer
--------------
Imagine some time goes by, during which Alice is happy with her bicycle, and
one day, she meets Bob, who is interested in acquiring her bicycle. The timing
is good for Alice as she had been wanting to get a new bicycle.
To transfer the bicycle (asset) to Bob, Alice must consume the transaction's output in
which the Bicycle asset was created.
Alice could retrieve the transaction:
.. code-block:: js
conn.getTransaction(txCreateAliceSimpleSigned.id)
First, let's prepare the transaction to be transferred.
.. code-block:: js
const txTransferBob = driver.Transaction.makeTransferTransaction(
// signedTx to transfer and output index
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
// metadata
{price: '100 euro'}
);
The function ``makeTransferTransaction()`` needs following parameters:
- Unspent outputs: Array of `unspent transactions outputs`. Each item contains `Transaction` itself and index of `unspent output` for that `Transaction`.
- Array of output objects to add to the transaction: Think of these as the recipients of the asset after the transaction. For `TRANSFER` transactions, this should usually just be a list of outputs wrapping Ed25519 conditions generated from the public keys of the recipients.
- Metadata for transaction (e.g. price of sold bike)
Fulfill transaction by signing it with Alice's private key.
.. code-block:: js
driver.Transaction.signTransaction(txTransferBob, alice.privateKey);
And sent over to a BigchainDB node:
.. code-block:: js
conn.postTransactionCommit(txTransferBobSigned)
Check the status again:
Bob is the new owner:
.. code-block:: js
console.log('Is Bob the owner?', txTransferBobSigned['outputs'][0]['public_keys'][0] == bob.publicKey)
// Output: true
Alice is the former owner:
.. code-block:: js
console.log('Was Alice the previous owner?', txTransferBobSigned['inputs'][0]['owners_before'][0] == alice.publicKey )
// Output: true
Querying for Assets
-------------------
BigchainDB allows you to query for assets using simple text search. This search is applied to all the strings inside the asset payload and returns all the assets that match a given text search string.
BigchainDB also allows you to query for metadata, but there are some differences. The response of the text search call, beside retrieving the asset or metadata in each case, it consist of:
- In the assets search the call returns the asset id which is the same id of the transaction that created the asset.
- In the metadata search the call returns the transaction id that contains this metadata.
Lets assume that we created 3 assets that look like this:
.. code-block:: js
assets = [
{'data': {'bicycle': {'serial_number': 'abc', manufacturer: 'Bicycle Inc.'}}},
{'data': {'bicycle': {'serial_number': 'cde', manufacturer: 'Bicycle Inc.'}}},
{'data': {'bicycle': {'serial_number': 'fgh', manufacturer: 'Bicycle Inc.'}}}
]
Lets perform a text search for all assets that contain the word 'Bicycle Inc.':
.. code-block:: js
conn.searchAssets('Bicycle Inc.')
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets))
Which leads to following result:
.. code-block:: js
[
{
'data': {'bicycle': {'serial_number': 'abc', manufacturer: 'Bicycle Inc.'}},
'id': '7582d7a81652d0230fefb47dafc360ff09b2c2566b68f05c3a004d57e7fe7610'
},
{
'data': {'bicycle': {'serial_number': 'cde', manufacturer: 'Bicycle Inc.'}},
'id': 'e40f4b6ac70b9c1b3b237ec13f4174384fd4d54d36dfde25520171577c49caa4'
},
{
'data': {'bicycle': {'serial_number': 'fgh', manufacturer: 'Bicycle Inc.'}},
'id': '748f6c30daaf771c9020d84db9ad8ac4d1f7c8de7013db55e16f10ba090f7013'
}
]
This call returns all the assets that match the string 'Bicycle Inc.', sorted by text score, as well as the asset id.
Querying for Metadata
---------------------
Similar as querying for assets, in BigchainDB you can query for metadata using simple text search.
This search is applied to all the strings inside the metadata payload and returns all the metadata payloads that match a given text search string.
Having 3 metadata objets that look like this:
.. code-block:: js
metadata = [
{'state': {'price': 145, 'eur/us': '1.32'}},
{'state': {'price': 236, 'eur/us': '1.15'}},
{'state': {'price': 102, 'eur/us': '1.32'}},
]
Lets perform a text search for all metadata that contains the word '1.32':
.. code-block:: js
conn.searchMetadata('1.32')
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets))
Which leads to following result:
.. code-block:: js
[
{
'metadata': {'state': {'price': 145, 'eur/us': '1.32'}},
'id': '14045a0e27ea971f8ac88762d2d74518d3a21f3f0fcd9d8a9a3b644b689cf3eb'
},
{
'metadata': {'state': {'price': 102, 'eur/us': '1.32'}},
'id': '6dd91f4700b3f66c55c50be009018e96f026d37f565d042d1aedfb322623d17d'
}
]
This call returns all the metadata objects that match the string '1.32', sorted by text score, as well as the transaction id corresponding to each metadata object.
Recap: Asset Creation & Transfer
--------------------------------
.. code-block:: js
const driver = require('bigchaindb-driver')
// BigchainDB server instance or testnetwork (e.g. https://example.com/api/v1/)
const API_PATH = 'http://localhost:9984/api/v1/'
// Create a new keypair for Alice and Bob
const alice = new driver.Ed25519Keypair()
const bob = new driver.Ed25519Keypair()
console.log('Alice: ', alice.publicKey)
console.log('Bob: ', bob.publicKey)
// Define the asset to store, in this example
// we store a bicycle with its serial number and manufacturer
const assetdata = {
'bicycle': {
'serial_number': 'cde',
'manufacturer': 'Bicycle Inc.',
}
}
// Metadata contains information about the transaction itself
// (can be `null` if not needed)
// E.g. the bicycle is fabricated on earth
const metadata = {'planet': 'earth'}
// Construct a transaction payload
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
metadata,
// A transaction needs an output
[ driver.Transaction.makeOutput(
driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
// Sign the transaction with private keys of Alice to fulfill it
const txCreateAliceSimpleSigned = driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
// Send the transaction off to BigchainDB
const conn = new driver.Connection(API_PATH)
conn.postTransactionCommit(txCreateAliceSimpleSigned)
.then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.'))
// With the postTransactionCommit if the response is correct, then the transaction
// is valid and commited to a block
// Transfer bicycle to Bob
.then(() => {
const txTransferBob = driver.Transaction.makeTransferTransaction(
// signedTx to transfer and output index
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
// metadata
{price: '100 euro'}
)
// Sign with alice's private key
let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
console.log('Posting signed transaction: ', txTransferBobSigned)
// Post with commit so transaction is validated and included in a block
return conn.postTransactionCommit(txTransferBobSigned)
})
.then(tx => {
console.log('Response from BDB server:', tx)
console.log('Is Bob the owner?', tx['outputs'][0]['public_keys'][0] == bob.publicKey)
console.log('Was Alice the previous owner?', tx['inputs'][0]['owners_before'][0] == alice.publicKey )
})
// Search for asset based on the serial number of the bicycle
.then(() => conn.searchAssets('Bicycle Inc.'))
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets))
Ed25519Keypair Seed Functionality
---------------------------------
BigchainDB JavaScript driver allows you to create a keypair based on a seed.
The constructor accepts a 32 byte seed. One of the ways to create a seed from
a string (e.g. a passphrase) is the one used by ``bip39``, specifically the function ``mnemonicToSeed``.
Install bip39 with npm: ``npm install bip39``
Next, require ``bip39`` in your file like this: ``var bip39 = require('bip39')``
At last, we can create the keypair based on a string. The function will transform the string to a byte array.
As our constructor ``Ed25519Keypair()`` only accepts a seed of 32 bytes, we slice the first 32 bytes: ``slice(0,32)``.
.. code-block:: js
var keypair = new driver.Ed25519Keypair(bip39.mnemonicToSeed("yourString").slice(0, 32))
You can use the ``Ed25519Keypair()`` constructor as well without seed.
.. code-block:: js
var keypair = new driver.Ed25519Keypair()
Websocket Event Stream API Usage
--------------------------------
The Event Stream API enables new ways to interact with BigchainDB,
making it possible for your application to subscribe
to all newlyconfirmed transactions that are happening in the system.
Below piece of code can be opened in your web browser.
It will connect to your websocket (if you are using the testnet, redefine
``var wsUri ='wss://insert-testnet-subdomain-here.com:443/api/v1/streams/valid_transactions'``).
This web page will display all validated transactions.
.. code-block:: html
<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket BigchainDB</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Websocket Script -->
<script language="javascript" type="text/javascript">
var wsUri = "ws://localhost:9985/api/v1/streams/valid_transactions";
var output;
var alertbox;
function init()
{
output = document.getElementById("output");
alertbox = document.getElementById("alert-box");
setWebSocket();
}
function setWebSocket()
{
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
function onOpen(evt)
{
writeAlertMessage("CONNECTED");
}
function onClose(evt)
{
writeAlertMessage("DISCONNECTED");
}
function onMessage(evt)
{
writeToScreen('<a href="#" class="list-group-item"><h4 class="list-group-item-heading">Valid Transaction</h4><p class="list-group-item-text">' + evt.data + '</p></a>');
}
function onError(evt)
{
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function closeConnection(evt)
{
websocket.close()
}
function writeToScreen(message)
{
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
function writeAlertMessage(message)
{
var alert = document.createElement("div");
alert.className = "alert alert-success";
alert.setAttribute("role", "alert");
alert.innerHTML = message;
alertbox.appendChild(alert);
}
/* Initialize websocket and attach all events */
window.addEventListener("load", init, false);
/* Event called on closing browser or refreshing page to close connection */
window.addEventListener("beforeunload", closeConnection, false);
</script>
<!-- HTML Template -->
<div class="container">
<h2>WebSocket API Stream Valid Transactions BigchainDB</h2>
<!-- Box for displaying all alerts -->
<div id="alert-box"></div>
<!-- Div for attachting all outputs -->
<div id="output" class="list-group"></div>
</div>
Besides that, a NodeJs version has been created to display the validated transactions.
All transactions are printed to the console. To use this piece of code, you will need the ``ws`` (WebSocket package) through npm: ``npm install --save ws``.
.. code-block:: js
const WebSocket = require('ws')
const ws = new WebSocket('ws://localhost:9985/api/v1/streams/valid_transactions')
ws.on('open', () => {
console.log("CONNECTED")
});
ws.on('message', (data) => {
let json = JSON.parse(data)
console.log("\nTransactionId: ", json.transaction_id)
console.log("AssetId: ", json.asset_id)
console.log("BlockId: ", json.block_id)
});
Difference unspent and spent output
-----------------------------------
An unspent output is simply an output of a transaction which isn't yet an input of another transaction.
So, if we transfer an asset, the output becomes spent, because it becomes the input of the transfer transaction.
The transfer transactions its output becomes unspent now until he transfers the asset again to somebody else.
We will demonstrate this with a piece of code where we transfer a bicycle from Alice to Bob,
and further we transfer it from Bob to Chris. Expectations:
* Output for Alice is spent
* Output for Bob is spent
* Output for Chris is unspent (he is the last person in transaction chain)
.. code-block:: js
const driver = require('bigchaindb-driver')
const API_PATH = 'http://localhost:9984/api/v1/'
const conn = new driver.Connection(API_PATH)
const alice = new driver.Ed25519Keypair()
const bob = new driver.Ed25519Keypair()
const chris = new driver.Ed25519Keypair()
console.log('Alice: ', alice.publicKey)
console.log('Bob: ', bob.publicKey)
console.log('Chris: ', chris.publicKey)
// Define the asset to store, in this example
// we store a bicycle with its serial number and manufacturer
assetdata = {
'bicycle': {
'serial_number': 'cde',
'manufacturer': 'Bicycle Inc.',
}
}
var txTransferBobSigned;
// Construct a transaction payload
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
{'meta': 'meta'},
// A transaction needs an output
[ driver.Transaction.makeOutput(
driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
// Sign the transaction with private keys of Alice to fulfill it
const txCreateAliceSimpleSigned = driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
console.log('\n\nPosting signed create transaction for Alice:\n', txCreateAliceSimpleSigned)
conn.postTransactionCommit(txCreateAliceSimpleSigned)
// Transfer bicycle from Alice to Bob
.then(() => {
const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
{'newOwner': 'Bob'}
)
// Sign with alice's private key
txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
console.log('\n\nPosting signed transaction to Bob:\n', txTransferBobSigned)
// Post with commit so transaction is validated and included in a block
return conn.postTransactionCommit(txTransferBobSigned)
})
// Second transfer of bicycle from Bob to Chris
.then(tx => {
const txTransferChris = driver.Transaction.makeTransferTransaction(
[{ tx: txTransferBobSigned, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(chris.publicKey))],
{'newOwner': 'Chris'}
)
// Sign with bob's private key
let txTransferChrisSigned = driver.Transaction.signTransaction(txTransferChris, bob.privateKey)
console.log('\n\nPosting signed transaction to Chris:\n', txTransferChrisSigned)
// Post with commit so transaction is validated and included in a block
return conn.postTransactionCommit(txTransferChrisSigned)
})
.then(() => conn.listOutputs(alice.publicKey, true))
.then(listSpentOutputs => {
console.log("\nSpent outputs for Alice: ", listSpentOutputs.length) // Spent outputs: 1
return conn.listOutputs(alice.publicKey, false)
})
.then(listUnspentOutputs => {
console.log("Unspent outputs for Alice: ", listUnspentOutputs.length) // Unspent outputs: 0
return conn.listOutputs(bob.publicKey, true)
})
.then(listSpentOutputs => {
console.log("\nSpent outputs for Bob: ", listSpentOutputs.length) // Spent outputs: 1
return conn.listOutputs(bob.publicKey, false)
})
.then(listUnspentOutputs => {
console.log("Unspent outputs for Bob: ", listUnspentOutputs.length) // Unspent outputs: 0
return conn.listOutputs(chris.publicKey, true)
})
.then(listSpentOutputs => {
console.log("\nSpent outputs for Chris: ", listSpentOutputs.length) // Spent outputs: 0
return conn.listOutputs(chris.publicKey, false)
})
.then(listUnspentOutputs => {
console.log("Unspent outputs for Chris: ", listUnspentOutputs.length) // Unspent outputs: 1
})
.catch(res => {console.log(res)})
Output of above code looks like this. As you can see, Chris has no spent output, but one unspent output.
.. code-block:: js
Spent outputs for Alice: 1
Unspent outputs for Alice: 0
Spent outputs for Bob: 1
Unspent outputs for Bob: 0
Spent outputs for Chris: 0
Unspent outputs for Chris: 1
Divisible Assets
----------------
All assets in BigchainDB become implicitly divisible if a transaction contains more than one of that asset (well see how this happens shortly).
Let's assume we have created a token to pay each other for small transactions like a beer or some food between friends.
.. code-block:: js
const token = {
'value': '1 euro'
}
Let's create the asset. Note that we give an extra parameter to the ``makeOutput()`` function.
We give it the parameter ``'4'`` to indicate that we want to create 4 tokens.
**Pay attention to give the function a String instead of a plain Number.**
.. code-block:: js
const txCreateAliceDivisible = driver.Transaction.makeCreateTransaction(
token,
{metaDataMessage: 'I am specific to this create transaction'},
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '4')],
alice.publicKey
)
Alice goes dining at Bob and Carly. She decides to give a small fee to Bob and Carly.
Alice decides to issue 4 tokens as a payment for her food: one to Bob, two to Carly and one to herself.
Why one to herself? If you decide to fulfill an output, you have to spend all tokens.
So if you want to keep one token for yourself, you have to transfer it to yourself.
As you can see, we fulfill the first output of the create transaction (it's 0 because we start counting from 0).
This gives us 4 tokens to transfer.
.. code-block:: js
const txTransferDivisible = driver.Transaction.makeTransferTransaction(
[{ tx: txCreateAliceDivisibleSigned, output_index: 0 }],
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(carly.publicKey), '2'),
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey), '1'),
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '1')
],
{
metaDataMessage: 'I am specific to this transfer transaction'
}
);
To make the use of the last parameter of ``makeTransferTransaction()`` function more clear, we will do another transfer.
We will fulfill the first and second output of the create transaction (0, 1) because Carly and Bob decide to redistribute some money.
* Output 0 represents 2 tokens for Carly
* Output 1 represents 1 token for Bob
This gives us 3 tokens to redistribute. I want to give 1 token to Carly and 2 tokens Alice.
.. code-block:: js
const txTransferDivisibleInputs = driver.Transaction.makeTransferTransaction(
[{ tx: txTransferDivisibleSigned, output_index: 0 }, { tx: txTransferDivisibleSigned, output_index: 1 }],
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(carly.publicKey), '1'),
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey), '2')
],
{
metaDataMessage: 'I am specific to this transfer transaction'
}
);
Because we want to fulfill two outputs (Carly and Bob), we have to sign the transfer transaction in the same order:
.. code-block:: js
const txTransferDivisibleInputsSigned = driver.Transaction.signTransaction(
txTransferDivisibleInputs,
carly.privateKey, bob.privateKey)
Here is a better overview of the flow of the tokens.
+-----------+------------+-----------------+
| **Owner** | **Amount** | **Transaction** |
+===========+============+=================+
| ``Alice`` | 4 | ``CREATE`` |
+-----------+------------+-----------------+
| ``Alice`` | 1 | ``TRANSFER 1`` |
+-----------+------------+-----------------+
| ``Bob`` | 1 | ``TRANSFER 1`` |
+-----------+------------+-----------------+
| ``Carly`` | 2 | ``TRANSFER 1`` |
+-----------+------------+-----------------+
| ``Alice`` | 3 | ``TRANSFER 2`` |
+-----------+------------+-----------------+
| ``Bob`` | 0 | ``TRANSFER 2`` |
+-----------+------------+-----------------+
| ``Carly`` | 1 | ``TRANSFER 2`` |
+-----------+------------+-----------------+
.. TODO:
.. - Add lexer: https://stackoverflow.com/questions/4259105/which-sphinx-code-block-language-to-use-for-json
.. - Add divisible assets example
.. - Add more readable code with promises possibly.

View File

@ -0,0 +1,114 @@
<!---
Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
--->
# Updating js-bigchaindb-driver from v0.1.x to v0.3.0
The latest version of js-bigchaindb-driver contains breaking changes to its
external API. In this document, we enumerate all changes to allow you to make
upgrades efficiently.
Note that upgrading the js-bigchaindb-driver to v0.3.0 was done to enable
functionality included in the latest (v1.0) BigchainDB release. A full list of
BigchainDB v1.0's breaking changes can be found
[here](https://github.com/bigchaindb/bigchaindb/blob/17913dca682ff105540c0ea73365f1763efc2083/docs/upgrade-guides/v0.10--%3Ev1.0.md).
Note that v1.0 [contains breaking changes to its core data
models](https://github.com/bigchaindb/bigchaindb/blob/17913dca682ff105540c0ea73365f1763efc2083/docs/upgrade-guides/v0.10--%3Ev1.0.md#breaking-changes-to-the-data-model).
This document will just go into the very specific breaking changes affecting
the JavaScript driver.
### Breaking changes to js-bigchaindb-driver's APIs
#### Output amount is now a string
```js
// old
export default function makeOutput(condition, amount = 1) {}
// new
export default function makeOutput(condition, amount = '1') {}
```
#### Update to Crypto-Conditions version 2
All conditions or fulfillments passed manually to the driver now need to comply
with ILP's Crypto-Condition version 2 specification. For more information,
[see the updated
specification](https://tools.ietf.org/html/draft-thomas-crypto-conditions-02)
or checkout the [latest reference implementation of Crypto-Conditions in
JavaScript](https://github.com/interledgerjs/five-bells-condition).
#### Several `Connection` methods now require positional arguments
##### `Connection.listBlocks`
```js
// old
new Connection(PATH).listBlocks({ tx_id, status })
// new
new Connection(PATH).listBlocks(transactionId, status)
```
##### `Connection.listOutputs`
```js
// old
new Connection(PATH).listOutputs({ public_key, unspent })
// new
new Connection(PATH).listOutputs(publicKey, spent)
```
**NOTE:** The `unspent` flag has been inversed. This is inline [with breaking
changes to BigchainDB
v1.0](https://github.com/bigchaindb/bigchaindb/blob/17913dca682ff105540c0ea73365f1763efc2083/docs/upgrade-guides/v0.10--%3Ev1.0.md#get-apiv1outputs).
##### `Connection.listTransactions`
```js
// old
new Connection(PATH).listTransactions({ asset_id, operation })
// new
new Connection(PATH).listTransactions(assetId, operation)
```
### Newly added endpoints
##### `Connection.searchAsset`
```js
// new
new Connection(PATH).searchAssets(search)
```
A querying interface to text-search all assets in BigchainDB. For more
documentation, [see BigchainDB's HTTP
API](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html#assets).
### Newly available bundles and CDN hosting
The driver is now bundled automatically each time we publish it to npm.com. We
now ship packages for `commonjs`, `commonjs2`, `amd`, `umd`, `window` and
node.js. Thanks to unpkg.com, we're also able to provide all these packages on
a CDN. A link to all the bundles can be found
[here](https://unpkg.com/bigchaindb-driver@0.3.0/dist/browser/).
A few notes:
- Adjust version number in link as appropriate
- only include `bigchaindb-driver.*.min.js`, but now everything `bundle.*`.
This is [a known
issue](https://github.com/bigchaindb/js-bigchaindb-driver/issues/66).

16
examples/.babelrc Normal file
View File

@ -0,0 +1,16 @@
{
"presets": [["@babel/preset-env"]],
"plugins": [
"@babel/plugin-syntax-async-generators",
[
"@babel/plugin-transform-runtime",
{
"absoluteRuntime": false,
"helpers": true,
"regenerator": true
}
],
"@babel/plugin-transform-regenerator",
"@babel/plugin-transform-async-to-generator"
]
}

1
examples/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

32
examples/README.md Normal file
View File

@ -0,0 +1,32 @@
<!---
Copyright BigchainDB GmbH and BigchainDB contributors
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0
--->
# Quick Notes
`dotenv` is listed as a dependencies in `package.json`.
If you want to use this, add a `.env` file to the root of this project (same level as this `README.md` file)
and replace the variables to fit your specific config.
```
BIGCHAINDB_API_PATH=https://test.bigchaindb.com/api/v1/
BIGCHAINDB_APP_ID=<your-app-id>
BIGCHAINDB_APP_KEY=<your-app-key>
```
# Usage
`npm install` -> Installs all required dependencies to run these examples.
## Different Examples
**Basic Usage**: Create asset and transfer it to new owner.
-> `npm start`
**Async/Await Basic Usage**: Basic usage example rewritten with async/await.
-> `npm run basic-async`
**Querying for Assets**: Query for assetdata or metadata.
-> `npm run query-assets`
**Seed/Keypair Functionality**: Create keypair with bip39 library.
-> `npm run seed-func`

38
examples/package.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "js-driver-bigchaindb-examples",
"version": "1.0.0",
"main": "src/basic-usage.js",
"scripts": {
"build": "npm run clean && babel src -d dist",
"serve": "node dist/basic-usage.js",
"clean": "rimraf ./dist",
"start": "nodemon src/basic-usage.js --exec babel-node",
"query-assets": "nodemon src/query-assets.js --exec babel-node",
"seed-func": "nodemon src/seed-func.js --exec babel-node",
"basic-async": "nodemon src/basic-usage-async-await.js --exec babel-node"
},
"author": "BigchainDB",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.8",
"@babel/eslint-parser": "^7.13.8",
"@babel/node": "7.13.0",
"@babel/plugin-syntax-async-generators": "^7.8.4",
"@babel/plugin-transform-async-to-generator": "^7.13.0",
"@babel/plugin-transform-regenerator": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.13.9",
"@babel/preset-env": "^7.13.9",
"@babel/register": "^7.13.8",
"babel-loader": "^8.2.2",
"nodemon": "^2.0.7",
"rimraf": "^3.0.2"
},
"repository": "/",
"private": true,
"dependencies": {
"bigchaindb-driver": "^4.1.2",
"bip39": "^3.0.3",
"dotenv": "^8.2.0"
}
}

View File

@ -0,0 +1,62 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable import/no-unresolved */
const driver = require('bigchaindb-driver')
require('dotenv').config()
// ======== Preparation ======== //
const conn = new driver.Connection('https://test.ipdb.io/api/v1/', {
header1: 'header1_value',
header2: 'header2_value'
})
const alice = new driver.Ed25519Keypair()
const bob = new driver.Ed25519Keypair()
const assetdata = {
'bicycle': {
'serial_number': 'abcd1234',
'manufacturer': 'Bicycle Inc.',
}
}
const metadata = { 'planet': 'earth' }
// Call async basic usage function
basicUsage()
async function basicUsage() {
// ======== Create Transaction Bicycle ======== //
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
metadata,
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
const txCreateAliceSimpleSigned =
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
// ======== POST CREATE Transaction ======== //
const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned)
// ======== POST TRANSFER Transaction ======== //
const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: createdTx, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
{ price: '100 euro' }
)
const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
await conn.postTransactionCommit(txTransferBobSigned)
// ======== Querying Assets ======== //
const assets = await conn.searchAssets('Bicycle Inc.')
console.log(assets) // eslint-disable-line no-console
}

View File

@ -0,0 +1,63 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable import/no-unresolved */
const driver = require('bigchaindb-driver')
require('dotenv').config()
// ======== Preparation ======== //
const conn = new driver.Connection('https://test.ipdb.io/api/v1/', {
header1: 'header1_value',
header2: 'header2_value'
})
const alice = new driver.Ed25519Keypair()
const bob = new driver.Ed25519Keypair()
const assetdata = {
'bicycle': {
'serial_number': 'abcd1234',
'manufacturer': 'Bicycle Inc.',
}
}
const metadata = { 'planet': 'earth' }
// ======== Create Transaction Bicycle ======== //
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
metadata,
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
const txCreateAliceSimpleSigned =
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
// ======== Post Transaction and Fetch Result ======== //
conn.postTransactionCommit(txCreateAliceSimpleSigned)
// ======== Transfer Bicycle to Bob ======== //
.then((fetchedTx) => {
const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: fetchedTx, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
{ price: '100 euro' }
)
// Sign transfer transaction with Alice's private key
const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
return conn.postTransactionCommit(txTransferBobSigned)
})
.then(tx => {
console.log('Is Bob the owner?', tx.outputs[0].public_keys[0] === bob.publicKey) // eslint-disable-line no-console
console.log('Was Alice the previous owner?', tx.inputs[0].owners_before[0] === alice.publicKey) // eslint-disable-line no-console
})
// ======== Search Asset by Serial Number ======== //
.then(() => conn.searchAssets('Bicycle Inc.'))
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets)) // eslint-disable-line no-console

View File

@ -0,0 +1,50 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable import/no-unresolved */
const driver = require('bigchaindb-driver')
require('dotenv').config()
// ======== Preparation ======== //
const conn = new driver.Connection('https://example.com/api/v1/', {
header1: 'header1_value',
header2: 'header2_value'
})
const alice = new driver.Ed25519Keypair()
// ======== Asset Array ======== //
const assetArray = []
assetArray.push({ 'bicycle': { 'serial_number': 'abc', 'manufacturer': 'BicyclesInc' } })
assetArray.push({ 'bicycle': { 'serial_number': 'cde', 'manufacturer': 'BicyclesInc' } })
assetArray.push({ 'bicycle': { 'serial_number': 'fgh', 'manufacturer': 'BicyclesInc' } })
const metadata = { 'planet': 'Pluto' }
// ======== Create Transactions for bicycles ======== //
function createTx(assetdata) {
const txCreate = driver.Transaction.makeCreateTransaction(
assetdata,
metadata,
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
const txCreateSigned = driver.Transaction.signTransaction(txCreate, alice.privateKey)
return conn.postTransactionCommit(txCreateSigned)
}
// ======== Execute all promises in order to post transactions and fetch them ======== //
Promise.all(assetArray.map(createTx))
// ======== Querying Assets for Assetdata ======== //
.then(() => conn.searchAssets('BicyclesInc'))
.then(assets => console.log('Found assets with serial number "BicyclesInc":', assets)) // eslint-disable-line no-console
// ======== Querying Assets for Metadata ======== //
.then(() => conn.searchMetadata('Pluto'))
.then(assets => console.log('Found assets with metadata "Pluto":', assets)) // eslint-disable-line no-console

40
examples/src/seed-func.js Normal file
View File

@ -0,0 +1,40 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable import/no-unresolved */
import bip39 from 'bip39'
const driver = require('bigchaindb-driver')
// ======== Create Keypair ======== //
/**
* Use a passphrase to derive a keypair
* If you use the same seed -> you will derive the same keypair
*
* mnemnoicToSeed() transforms the passphrase you gave as an input
* to a byteArray
*
* BigchainDB however only accepts an input length of 32 characters
* so we have to slice this to give it as input for driver.Ed25519Keypair()
*
* Is it safe to slice? Yes, a seed of length 32 is very safe according
* to related papers discussing this.
*/
const passphrase = 'This is a random passphrase'
const seed = bip39.mnemonicToSeed(passphrase).slice(0, 32)
const keypair = new driver.Ed25519Keypair(seed)
console.log(`Public Key: ${keypair.publicKey} - Private Key: ${keypair.privateKey}`) // eslint-disable-line no-console
// ======== Other Bip39 Functionality not related to BigchainDB ======== //
/* Create Random passphrase */
const mnemonic = bip39.generateMnemonic()
console.log('Random passphrase: ', mnemonic) // eslint-disable-line no-console
/* Validate mnemnoic */
console.log(bip39.validateMnemonic(mnemonic)) // eslint-disable-line no-console
console.log(bip39.validateMnemonic('some random strings together but to short')) // eslint-disable-line no-console

View File

@ -1,6 +1,6 @@
{
"name": "bigchaindb-driver",
"version": "0.1.0",
"version": "4.3.0",
"description": "Node.js driver for BigchainDB",
"homepage": "https://www.bigchaindb.com/",
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",
@ -10,62 +10,83 @@
},
"license": "Apache-2.0",
"author": "BigchainDB",
"files": [
"dist",
"types"
],
"main": "./dist/node/index.js",
"browser": "./dist/browser/bundle.min.js",
"browser": "./dist/browser/bigchaindb-driver.cjs2.min.js",
"types": "./types/index.d.ts",
"sideEffects": false,
"scripts": {
"lint": "eslint ./",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"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",
"clean": "rimraf dist/bundle dist/node",
"test": "npm run lint && ava",
"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",
"prepublish": "npm update && npm run build",
"precommit": "npm run lint"
"build:dist": "cross-env NODE_ENV=production webpack",
"dev": "webpack -w",
"clean": "rimraf dist/bundle dist/browser dist/node",
"test": "npm run lint && nyc ava && npm run report-coverage",
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",
"release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it --src.tagName='v%s'",
"release-minor": "release-it minor --non-interactive",
"release-major": "release-it major --non-interactive",
"prepublishOnly": "npm run build",
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
"doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc"
},
"devDependencies": {
"ava": "^0.19.1",
"babel-cli": "^6.22.2",
"babel-eslint": "^7.1.1",
"babel-loader": "^7.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.23.0",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015-no-commonjs": "0.0.2",
"babel-preset-latest": "^6.22.0",
"babel-runtime": "^6.22.0",
"cross-env": "^5.0.1",
"eslint": "^3.14.1",
"eslint-config-ascribe": "^3.0.1",
"eslint-plugin-import": "^2.2.0",
"husky": "^0.13.4",
"release-it": "^2.7.3",
"rimraf": "^2.5.4",
"webpack": "^2.2.1"
"@ava/babel": "^2.0.0",
"@babel/cli": "^7.17.0",
"@babel/core": "^7.17.2",
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-proposal-export-default-from": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
"@babel/plugin-syntax-async-generators": "^7.8.4",
"@babel/plugin-transform-async-to-generator": "^7.16.8",
"@babel/plugin-transform-object-assign": "^7.16.7",
"@babel/plugin-transform-regenerator": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/register": "^7.17.0",
"ava": "^3.15.0",
"babel-loader": "^8.2.2",
"buffer": "^6.0.3",
"codecov": "^3.8.1",
"cross-env": "^7.0.3",
"documentation": "^13.2.5",
"eslint": "^8.9.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"husky": "^7.0.4",
"lint-staged": "^12.3.4",
"nyc": "^15.1.0",
"release-it": "^14.12.4",
"rewire": "^6.0.0",
"rimraf": "^3.0.2",
"sinon": "^13.0.1",
"terser-webpack-plugin": "^5.3.1",
"webpack": "^5.68.0",
"webpack-cli": "^4.9.2",
"webpack-merge": "^5.8.0",
"webpack-sources": "^3.2.3"
},
"dependencies": {
"browser-resolve": "^1.11.2",
"bs58": "^4.0.0",
"buffer": "^5.0.2",
"clone": "^2.1.0",
"core-js": "^2.4.1",
"decamelize": "^1.2.0",
"es6-promise": "^4.0.5",
"fetch-ponyfill": "^4.0.0",
"five-bells-condition": "3.3.1",
"isomorphic-fetch": "^2.2.1",
"js-sha3": "^0.5.7",
"js-utility-belt": "^1.5.0",
"@babel/runtime-corejs3": "^7.17.2",
"abort-controller": "^3.0.0",
"bs58": "^4.0.1",
"clone": "^2.1.2",
"core-js": "^3.21.0",
"crypto-conditions": "2.2.1",
"decamelize": "^5.0.0",
"es6-promise": "^4.2.8",
"fetch-ponyfill": "^7.1.0",
"js-sha3": "^0.8.0",
"json-stable-stringify": "^1.0.1",
"query-string": "^4.3.4",
"sprintf-js": "^1.0.3",
"tweetnacl": "^1.0.0"
"query-string": "^7.1.1",
"sprintf-js": "^1.1.2",
"tweetnacl": "^1.0.3"
},
"keywords": [
"bigchaindb",
@ -74,9 +95,15 @@
"decentralized",
"dapp"
],
"lint-staged": {
"*.js": [
"eslint"
]
},
"ava": {
"files": [
"test/*.js"
"test/**/*.js",
"!test/constants.js"
],
"source": [
"**/*.{js,jsx}",
@ -88,8 +115,29 @@
"tap": true,
"powerAssert": false,
"require": [
"babel-register"
"@babel/register"
],
"babel": "inherit"
"babel": true
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"release-it": {
"github": {
"release": true
},
"git": {
"tagName": "v${version}"
},
"hooks": {
"before:init": [
"npm run test"
]
},
"npm": {
"publish": true
}
}
}

View File

@ -0,0 +1,38 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable strict, no-console, object-shorthand, import/no-extraneous-dependencies */
const { ConcatSource } = require('webpack-sources')
module.exports = class AddVendorsPlugin {
constructor(base) {
this.base = base
}
apply(compiler) {
compiler.hooks.emit.tapAsync(
`AddVendorsPlugin ${this.base}`,
(compilation, callback) => {
const main = compilation.assets[`main.${this.base}`]
const mainMap = compilation.assets[`main.${this.base}.map`]
const vendor = compilation.assets[`vendors.${this.base}`]
if (main && vendor) {
const compiledAsset = new ConcatSource(main._value[0])
compiledAsset.add(vendor)
compiledAsset.add(main._value[1])
compilation.assets = {}
compilation.assets[this.base] = compiledAsset
} else if (main && mainMap) {
compilation.assets = {}
compilation.assets[this.base] = main
compilation.assets[`${this.base}.map`] = mainMap
}
callback()
}
)
}
}

View File

@ -1,17 +1,21 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import base58 from 'bs58'
import nacl from 'tweetnacl'
import { sign } from 'tweetnacl'
/**
* @public
* @class Keypair Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* @type {Object}
* @param {Buffer} [seed] A seed that will be used as a key derivation function
* @property {string} publicKey
* @property {string} privateKey
*/
export default function Ed25519Keypair(seed) {
const keyPair = seed ? nacl.sign.keyPair.fromSeed(seed) : nacl.sign.keyPair()
this.publicKey = base58.encode(keyPair.publicKey)
const keyPair = seed ? sign.keyPair.fromSeed(seed) : sign.keyPair()
this.publicKey = base58.encode(Buffer.from(keyPair.publicKey))
// tweetnacl's generated secret key is the secret key + public key (resulting in a 64-byte buffer)
this.privateKey = base58.encode(keyPair.secretKey.slice(0, 32))
this.privateKey = base58.encode(Buffer.from(keyPair.secretKey.slice(0, 32)))
}

View File

@ -1,16 +1,78 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
// TODO: remove abort-controller when using Node >=15
import AbortController from 'abort-controller'
import { Promise } from 'es6-promise'
import fetchPonyfill from 'fetch-ponyfill'
import { vsprintf } from 'sprintf-js'
import formatText from './format_text'
import stringifyAsQueryParam from './stringify_as_query_param'
const fetch = fetchPonyfill({ Promise })
const fetch = fetchPonyfill(Promise)
export function ResponseError(message, status, requestURI) {
this.name = 'ResponseError'
this.message = message
this.status = status
this.requestURI = requestURI
this.stack = new Error().stack
}
ResponseError.prototype = new Error()
/**
* @private
* Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564
* @param {integer} obj Source object
* @param {Promise} filter Array of key names to select or function to invoke per iteration
* @param {AbortController} controller AbortController instance bound to fetch
* @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved
*/
function timeout(ms, promise, controller) {
return new Promise((resolve, reject) => {
const nodeTimeout = setTimeout(() => {
controller.abort()
const errorObject = {
message: 'TimeoutError',
}
reject(new Error(errorObject))
}, ms)
promise
.then((res) => {
clearTimeout(nodeTimeout)
resolve(res)
})
.catch((err) => {
clearTimeout(nodeTimeout)
reject(err)
})
})
}
/**
* @private
* @param {Promise} res Source object
* @return {Promise} Promise that will resolve with the response if its status was 2xx;
* otherwise rejects with the response
*/
function handleResponse(res) {
// If status is not a 2xx (based on Response.ok), assume it's an error
// See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch
if (!(res && res.ok)) {
throw new ResponseError(
'HTTP Error: Requested page not reachable',
`${res.status} ${res.statusText}`,
res.url
)
}
return res
}
/**
* @private
* imported from https://github.com/bigchaindb/js-utility-belt/
*
* Global fetch wrapper that adds some basic error handling and ease of use enhancements.
@ -24,33 +86,44 @@ const fetch = fetchPonyfill(Promise)
* @param {string} url Url to request. Can be specified as a sprintf format string (see
* https://github.com/alexei/sprintf.js) that will be resolved using
* `config.urlTemplateSpec`.
* @param {object} config Additional configuration, mostly passed to fetch as its 'init' config
* @param {Object} config Additional configuration, mostly passed to fetch as its 'init' config
* (see https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch#Parameters).
* @param {*} config.jsonBody Json payload to the request. Will automatically be
* JSON.stringify()-ed and override `config.body`.
* @param {string|object} config.query Query parameter to append to the end of the url.
* @param {string|Object} config.query Query parameter to append to the end of the url.
* If specified as an object, keys will be
* decamelized into snake case first.
* @param {*[]|object} config.urlTemplateSpec Format spec to use to expand the url (see sprintf).
* @param {*[]|Object} config.urlTemplateSpec Format spec to use to expand the url (see sprintf).
* @param {*} config.* All other options are passed through to fetch.
* @param {integer} requestTimeout Timeout for a single request
*
* @return {Promise} Promise that will resolve with the response if its status was 2xx;
* otherwise rejects with the response
* @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the
* Promise with the handleResponse function
*/
export default function baseRequest(url, { jsonBody, query, urlTemplateSpec, ...fetchConfig } = {}) {
export default function baseRequest(
url,
{
jsonBody, query, urlTemplateSpec, ...fetchConfig
} = {},
requestTimeout = 0
) {
let expandedUrl = url
if (urlTemplateSpec != null) {
if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) {
// Use vsprintf for the array call signature
expandedUrl = vsprintf(url, urlTemplateSpec)
} else if (urlTemplateSpec &&
typeof urlTemplateSpec === 'object' &&
Object.keys(urlTemplateSpec).length) {
} else if (
urlTemplateSpec &&
typeof urlTemplateSpec === 'object' &&
Object.keys(urlTemplateSpec).length
) {
expandedUrl = formatText(url, urlTemplateSpec)
} else if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.warn('Supplied urlTemplateSpec was not an array or object. Ignoring...')
console.warn(
'Supplied urlTemplateSpec was not an array or object. Ignoring...'
)
}
}
@ -69,13 +142,16 @@ export default function baseRequest(url, { jsonBody, query, urlTemplateSpec, ...
fetchConfig.body = JSON.stringify(jsonBody)
}
return fetch.fetch(expandedUrl, fetchConfig)
.then((res) => {
// If status is not a 2xx (based on Response.ok), assume it's an error
// See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch
if (!(res && res.ok)) {
throw res
}
return res
})
if (requestTimeout) {
const controller = new AbortController()
const { signal } = controller
return timeout(
requestTimeout,
fetch.fetch(expandedUrl, { ...fetchConfig, signal }),
controller
)
.then(handleResponse)
} else {
return fetch.fetch(expandedUrl, fetchConfig).then(handleResponse)
}
}

201
src/connection.js Normal file
View File

@ -0,0 +1,201 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import Transport from './transport'
const HEADER_BLACKLIST = ['content-type']
const DEFAULT_NODE = 'http://localhost:9984/api/v1/'
const DEFAULT_TIMEOUT = 20000 // The default value is 20 seconds
/**
*
* @param {String, Array} nodes Nodes for the connection. String possible to be backwards compatible
* with version before 4.1.0 version
* @param {Object} headers Common headers for every request
* @param {float} timeout Optional timeout in secs
*
*
*/
export default class Connection {
// This driver implements the BEP-14 https://github.com/bigchaindb/BEPs/tree/master/14
constructor(nodes, headers = {}, timeout = DEFAULT_TIMEOUT) {
// Copy object
this.headers = { ...headers }
// Validate headers
Object.keys(headers).forEach(header => {
if (HEADER_BLACKLIST.includes(header.toLowerCase())) {
throw new Error(`Header ${header} is reserved and cannot be set.`)
}
})
this.normalizedNodes = []
if (!nodes) {
this.normalizedNodes.push(Connection.normalizeNode(DEFAULT_NODE, this.headers))
} else if (Array.isArray(nodes)) {
nodes.forEach(node => {
this.normalizedNodes.push(Connection.normalizeNode(node, this.headers))
})
} else {
this.normalizedNodes.push(Connection.normalizeNode(nodes, this.headers))
}
this.transport = new Transport(this.normalizedNodes, timeout)
}
static normalizeNode(node, headers) {
if (typeof node === 'string') {
return { 'endpoint': node, 'headers': headers }
} else {
const allHeaders = { ...headers, ...node.headers }
return { 'endpoint': node.endpoint, 'headers': allHeaders }
}
}
static getApiUrls(endpoint) {
return {
'blocks': 'blocks',
'blocksDetail': 'blocks/%(blockHeight)s',
'outputs': 'outputs',
'transactions': 'transactions',
'transactionsSync': 'transactions?mode=sync',
'transactionsAsync': 'transactions?mode=async',
'transactionsCommit': 'transactions?mode=commit',
'transactionsDetail': 'transactions/%(transactionId)s',
'assets': 'assets',
'metadata': 'metadata'
}[endpoint]
}
_req(path, options = {}) {
return this.transport.forwardRequest(path, options)
}
/**
* @param blockHeight
*/
getBlock(blockHeight) {
return this._req(Connection.getApiUrls('blocksDetail'), {
urlTemplateSpec: {
blockHeight
}
})
}
/**
* @param transactionId
*/
getTransaction(transactionId) {
return this._req(Connection.getApiUrls('transactionsDetail'), {
urlTemplateSpec: {
transactionId
}
})
}
/**
* @param transactionId
* @param status
*/
listBlocks(transactionId) {
return this._req(Connection.getApiUrls('blocks'), {
query: {
transaction_id: transactionId,
}
})
}
/**
* @param publicKey
* @param spent
*/
listOutputs(publicKey, spent) {
const query = {
public_key: publicKey
}
// NOTE: If `spent` is not defined, it must not be included in the
// query parameters.
if (spent !== undefined) {
query.spent = spent.toString()
}
return this._req(Connection.getApiUrls('outputs'), {
query
})
}
/**
* @param assetId
* @param operation
*/
listTransactions(assetId, operation) {
return this._req(Connection.getApiUrls('transactions'), {
query: {
asset_id: assetId,
operation
}
})
}
/**
* @param transaction
*/
postTransaction(transaction) {
return this.postTransactionCommit(transaction)
}
/**
* @param transaction
*/
postTransactionSync(transaction) {
return this._req(Connection.getApiUrls('transactionsSync'), {
method: 'POST',
jsonBody: transaction
})
}
/**
* @param transaction
*/
postTransactionAsync(transaction) {
return this._req(Connection.getApiUrls('transactionsAsync'), {
method: 'POST',
jsonBody: transaction
})
}
/**
* @param transaction
*/
postTransactionCommit(transaction) {
return this._req(Connection.getApiUrls('transactionsCommit'), {
method: 'POST',
jsonBody: transaction
})
}
/**
* @param search
*/
searchAssets(search, limit = 10) {
return this._req(Connection.getApiUrls('assets'), {
query: {
search,
limit
}
})
}
/**
* @param search
*/
searchMetadata(search, limit = 10) {
return this._req(Connection.getApiUrls('metadata'), {
query: {
search,
limit
}
})
}
}

View File

@ -1,174 +0,0 @@
import request from '../request'
export default class Connection {
constructor(path, headers) {
this.path = path
this.headers = headers
}
getApiUrls(endpoints) {
// TODO: Use camel case
return {
'blocks': `${this.path}blocks`,
'blocks_detail': `${this.path}blocks/%(blockId)s`,
'outputs': `${this.path}outputs`,
'statuses': `${this.path}statuses`,
'transactions': `${this.path}transactions`,
'transactions_detail': `${this.path}transactions/%(txId)s`,
'search_assets': `${this.path}assets`,
'votes': `${this.path}votes`
}[endpoints]
}
_req(path, options = {}) {
// NOTE: `options.headers` could be undefined, but that's OK.
options.headers = Object.assign({}, options.headers, this.headers)
return request(path, options)
}
/**
* @public
* @param blockId
*/
getBlock(blockId) {
return this._req(this.getApiUrls('blocks_detail'), {
urlTemplateSpec: {
blockId
}
})
}
/**
* @public
* @param tx_id
*/
getStatus(tx_id) { // eslint-disable-line camelcase
return this._req(this.getApiUrls('statuses'), {
query: {
tx_id
}
})
}
/**
* @public
* @param txId
*/
getTransaction(txId) {
return this._req(this.getApiUrls('transactions_detail'), {
urlTemplateSpec: {
txId
}
})
}
/**
* @public
* @param tx_id
* @param status
*/
listBlocks({ tx_id, status }) {
return this._req(this.getApiUrls('blocks'), {
query: {
tx_id,
status
}
})
}
/**
* @public
* @param public_key
* @param unspent
* @param onlyJsonResponse
*/
listOutputs({ public_key, unspent }, onlyJsonResponse = true) {
return this._req(this.getApiUrls('outputs'), {
query: {
public_key,
unspent
}
}, onlyJsonResponse)
}
/**
* @public
* @param asset_id
* @param operation
*/
listTransactions({ asset_id, operation }) {
return this._req(this.getApiUrls('transactions'), {
query: {
asset_id,
operation
}
})
}
/**
* @public
* @param block_id
*/
listVotes(block_id) { // eslint-disable-line camelcase
return this._req(this.getApiUrls('votes'), {
query: {
block_id
}
})
}
/**
* @public
* @param txId
* @return {Promise}
*/
pollStatusAndFetchTransaction(txId) {
return new Promise((resolve, reject) => {
const timer = setInterval(() => {
this.getStatus(txId)
.then((res) => {
console.log('Fetched transaction status:', res) // eslint-disable-line no-console
if (res.status === 'valid') {
clearInterval(timer)
this.getTransaction(txId)
.then((res_) => {
console.log('Fetched transaction:', res_) // eslint-disable-line no-console
resolve(res_)
})
}
})
.catch((err) => {
clearInterval(timer)
reject(err)
})
}, 500)
})
}
/**
* @public
*
* @param transaction
*/
postTransaction(transaction) {
return this._req(this.getApiUrls('transactions'), {
method: 'POST',
jsonBody: transaction
})
}
/**
* @public
*
* @param transaction
*/
searchAssets(query) {
return this.req(this.getApiUrls('search_assets'), {
query: {
text_search: query
}
})
}
}

View File

@ -1,5 +1,8 @@
import { sprintf } from 'sprintf-js'
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import { sprintf } from 'sprintf-js'
// Regexes taken from or inspired by sprintf-js
const Regex = {
@ -11,7 +14,7 @@ const Regex = {
/**
* imported from https://github.com/bigchaindb/js-utility-belt/
*
* @private
* Formats strings similarly to C's sprintf, with the addition of '${...}' formats.
*
* Makes a first pass replacing '${...}' formats before passing the expanded string and other
@ -47,6 +50,7 @@ export default function formatText(s, ...argv) {
let interpolationLeft = replacement
/**
* @private
* Interpolation algorithm inspired by sprintf-js.
*
* Goes through the replacement string getting the left-most key or index to interpolate
@ -69,7 +73,7 @@ export default function formatText(s, ...argv) {
// Assigning in the conditionals here makes the code less bloated
/* eslint-disable no-cond-assign */
while ((interpolationLeft = interpolationLeft.substring(curMatch[0].length)) &&
value != null) {
value != null) {
if ((curMatch = Regex.KEY_ACCESS.exec(interpolationLeft))) {
value = value[curMatch[1]]
} else if ((curMatch = Regex.INDEX_ACCESS.exec(interpolationLeft))) {
@ -84,9 +88,7 @@ export default function formatText(s, ...argv) {
// If there's anything left to interpolate by the end then we've failed to interpolate
// the entire replacement string.
if (interpolationLeft.length) {
throw new SyntaxError(
`[formatText] failed to parse named argument key: ${replacement}`
)
throw new SyntaxError(`[formatText] failed to parse named argument key: ${replacement}`)
}
return value

View File

@ -1,5 +1,13 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
export Ed25519Keypair from './Ed25519Keypair'
import Ed25519Keypair from './Ed25519Keypair'
import Connection from './connection'
import Transaction from './transaction'
import ccJsonLoad from './utils/ccJsonLoad'
import ccJsonify from './utils/ccJsonify'
export * as Transaction from './transaction'
export Connection from './connection'
export {
ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction
}

View File

@ -1,41 +1,118 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import baseRequest from './baseRequest'
import sanitize from './sanitize'
const DEFAULT_REQUEST_CONFIG = {
headers: {
'Accept': 'application/json'
}
}
const BACKOFF_DELAY = 500 // 0.5 seconds
const ERROR_FROM_SERVER = 'HTTP Error: Requested page not reachable'
/**
* @private
* Small wrapper around js-utility-belt's request that provides url resolving,
* default settings, and response handling.
*/
export default function request(url, config = {}, onlyJsonResponse = true) {
// Load default fetch configuration and remove any falsy query parameters
const requestConfig = Object.assign({}, DEFAULT_REQUEST_CONFIG, config, {
query: config.query && sanitize(config.query)
})
const apiUrl = url
if (requestConfig.jsonBody) {
requestConfig.headers = Object.assign({}, requestConfig.headers, {
'Content-Type': 'application/json'
})
}
if (!url) {
return Promise.reject(new Error('Request was not given a url.'))
export default class Request {
constructor(node) {
this.node = node
this.backoffTime = null
this.retries = 0
this.connectionError = null
}
return baseRequest(apiUrl, requestConfig)
.then((res) => onlyJsonResponse ? res.json() : // eslint-disable-line no-confusing-arrow
{
json: res.json(),
url: res.url
})
.catch((err) => {
console.error(err)
throw err
async request(urlPath, config, timeout, maxBackoffTime) {
if (!urlPath) {
return Promise.reject(new Error('Request was not given a url.'))
}
// Load default fetch configuration and remove any falsy query parameters
const requestConfig = {
...this.node.headers,
...DEFAULT_REQUEST_CONFIG,
...config,
query: config.query && sanitize(config.query)
}
const apiUrl = this.node.endpoint + urlPath
if (requestConfig.jsonBody) {
requestConfig.headers = { ...requestConfig.headers, 'Content-Type': 'application/json' }
}
// If connectionError occurs, a timestamp equal to now +
// `backoffTimedelta` is assigned to the object.
// Next time the function is called, it either
// waits till the timestamp is passed or raises `TimeoutError`.
// If `ConnectionError` occurs two or more times in a row,
// the retry count is incremented and the new timestamp is calculated
// as now + the `backoffTimedelta`
// The `backoffTimedelta` is the minimum between the default delay
// multiplied by two to the power of the
// number of retries or timeout/2 or 10. See Transport class for that
// If a request is successful, the backoff timestamp is removed,
// the retry count is back to zero.
const backoffTimedelta = this.getBackoffTimedelta()
if (timeout != null && timeout < backoffTimedelta) {
const errorObject = {
message: 'TimeoutError'
}
throw errorObject
}
if (backoffTimedelta > 0) {
await Request.sleep(backoffTimedelta)
}
const requestTimeout = timeout ? timeout - backoffTimedelta : timeout
return baseRequest(apiUrl, requestConfig, requestTimeout)
.then((res) => {
this.connectionError = null
return res.json()
})
.catch(err => {
// ConnectionError
this.connectionError = err
})
.finally(() => {
this.updateBackoffTime(maxBackoffTime)
})
}
updateBackoffTime(maxBackoffTime) {
if (!this.connectionError) {
this.retries = 0
this.backoffTime = null
} else if (this.connectionError.message === ERROR_FROM_SERVER) {
// If status is not a 2xx (based on Response.ok), throw error
this.retries = 0
this.backoffTime = null
throw this.connectionError
} else {
// Timeout or no connection could be stablished
const backoffTimedelta = Math.min(BACKOFF_DELAY * (2 ** this.retries), maxBackoffTime)
this.backoffTime = Date.now() + backoffTimedelta
this.retries += 1
if (this.connectionError.message === 'TimeoutError') {
throw this.connectionError
}
}
}
getBackoffTimedelta() {
if (!this.backoffTime) {
return 0
}
return (this.backoffTime - Date.now())
}
static sleep(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
}

View File

@ -1,36 +1,41 @@
import coreIncludes from 'core-js/library/fn/array/includes'
import coreObjectEntries from 'core-js/library/fn/object/entries'
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import 'core-js/features/array/includes'
import 'core-js/features/object/entries'
/**
* @private
* Abstraction for selectFromObject and omitFromObject for DRYness.
* Set isInclusion to true if the filter should be for including the filtered items (ie. selecting
* only them vs omitting only them).
*/
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
if (filter && Array.isArray(filter)) {
return applyFilterOnObject(obj, isInclusion ? ((_, key) => coreIncludes(filter, key))
: ((_, key) => !coreIncludes(filter, key)))
return applyFilterOnObject(obj, isInclusion ? (val => filter.includes(val))
: (val => !filter.includes(val)))
} 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')
throw new Error('The given filter is not an array or function. Filter aborted')
}
}
/**
* @private
* Returns a filtered copy of the given object's own enumerable properties (no inherited
* properties), keeping any keys that pass the given filter function.
*/
function applyFilterOnObject(obj, filterFn) {
if (filterFn == null) {
return Object.assign({}, obj)
return { ...obj }
}
const filteredObj = {}
coreObjectEntries(obj).forEach(([key, val]) => {
Object.entries(obj).forEach(([key, val]) => {
if (filterFn(val, key)) {
filteredObj[key] = val
}
@ -40,24 +45,26 @@ function applyFilterOnObject(obj, filterFn) {
}
/**
* @private
* Similar to lodash's _.pick(), this returns a copy of the given object's
* own and inherited enumerable properties, selecting only the keys in
* the given array or whose value pass the given filter function.
* @param {object} obj Source object
* @param {array|function} filter Array of key names to select or function to invoke per iteration
* @return {object} The new object
* @param {Object} obj Source object
* @param {Array|function} filter Array of key names to select or function to invoke per iteration
* @return {Object} The new object
*/
function selectFromObject(obj, filter) {
return filterFromObject(obj, filter)
}
/**
* @private
* Glorified selectFromObject. Takes an object and returns a filtered shallow copy that strips out
* any properties that are falsy (including coercions, ie. undefined, null, '', 0, ...).
* Does not modify the passed in object.
*
* @param {object} obj Javascript object
* @return {object} Sanitized Javascript object
* @param {Object} obj Javascript object
* @return {Object} Sanitized Javascript object
*/
export default function sanitize(obj) {
return selectFromObject(obj, (val) => !!val)

View File

@ -1,8 +1,14 @@
import sha3 from 'js-sha3'
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable camelcase */
import { sha3_256 } from 'js-sha3'
export default function sha256Hash(data) {
return sha3.sha3_256
return sha3_256
.create()
.update(data)
.hex()
}
/* eslint-enable camelcase */

View File

@ -1,9 +1,13 @@
import coreObjectEntries from 'core-js/library/fn/object/entries'
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import 'core-js/features/object/entries'
import decamelize from 'decamelize'
import queryString from 'query-string'
/**
* @private
* imported from https://github.com/bigchaindb/js-utility-belt/
*
* Takes a key-value dictionary (ie. object) and converts it to a query-parameter string that you
@ -24,7 +28,7 @@ import queryString from 'query-string'
*
* ?page=1&page_size=10
*
* @param {object} obj Query params dictionary
* @param {Object} obj Query params dictionary
* @param {function} [transform=decamelize] Transform function for each of the param keys
* @return {string} Query param string
*/
@ -33,7 +37,7 @@ export default function stringifyAsQueryParam(obj, transform = decamelize) {
return ''
}
const transformedKeysObj = coreObjectEntries(obj).reduce((paramsObj, [key, value]) => {
const transformedKeysObj = Object.entries(obj).reduce((paramsObj, [key, value]) => {
paramsObj[transform(key)] = value
return paramsObj
}, {})

287
src/transaction.js Normal file
View File

@ -0,0 +1,287 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import stableStringify from 'json-stable-stringify'
import clone from 'clone'
import base58 from 'bs58'
import { Ed25519Sha256, PreimageSha256, ThresholdSha256 } from 'crypto-conditions'
import ccJsonify from './utils/ccJsonify'
import sha256Hash from './sha256Hash'
/**
* Construct Transactions
*/
export default class Transaction {
/**
* Canonically serializes a transaction into a string by sorting the keys
* @param {Object} (transaction)
* @return {string} a canonically serialized Transaction
*/
static serializeTransactionIntoCanonicalString(transaction) {
// BigchainDB signs fulfillments by serializing transactions into a
// "canonical" format where
const tx = clone(transaction)
// TODO: set fulfillments to null
// Sort the keys
return stableStringify(tx, (a, b) => (a.key > b.key ? 1 : -1))
}
static makeInputTemplate(publicKeys = [], fulfills = null, fulfillment = null) {
return {
fulfillment,
fulfills,
'owners_before': publicKeys,
}
}
static makeTransactionTemplate() {
const txTemplate = {
id: null,
operation: null,
outputs: [],
inputs: [],
metadata: null,
asset: null,
version: '2.0',
}
return txTemplate
}
static makeTransaction(operation, asset, metadata = null, outputs = [], inputs = []) {
const tx = Transaction.makeTransactionTemplate()
tx.operation = operation
tx.asset = asset
tx.metadata = metadata
tx.inputs = inputs
tx.outputs = outputs
return tx
}
/**
* Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
* the `issuers`.
* @param {Object} asset Created asset's data
* @param {Object} metadata Metadata for the Transaction
* @param {Object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.
* For `CREATE` Transactions, this should usually just be a list of
* Outputs wrapping Ed25519 Conditions generated from the issuers' public
* keys (so that the issuers are the recipients of the created asset).
* @param {...string[]} issuers Public key of one or more issuers to the asset being created by this
* Transaction.
* Note: Each of the private keys corresponding to the given public
* keys MUST be used later (and in the same order) when signing the
* Transaction (`signTransaction()`).
* @returns {Object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!
*/
static makeCreateTransaction(asset, metadata, outputs, ...issuers) {
const assetDefinition = {
data: asset || null,
}
const inputs = issuers.map((issuer) => Transaction.makeInputTemplate([issuer]))
return Transaction.makeTransaction('CREATE', assetDefinition, metadata, outputs, inputs)
}
/**
* Create an Ed25519 Cryptocondition from an Ed25519 public key
* to put into an Output of a Transaction
* @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/
static makeEd25519Condition(publicKey, json = true) {
const publicKeyBuffer = base58.decode(publicKey)
const ed25519Fulfillment = new Ed25519Sha256()
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
return json ? ccJsonify(ed25519Fulfillment) : ed25519Fulfillment
}
/**
* Create an Output from a Condition.
* Note: Assumes the given Condition was generated from a
* single public key (e.g. a Ed25519 Condition)
* @param {Object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {string} amount Amount of the output
* @returns {Object} An Output usable in a Transaction
*/
static 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.subconditions.map(getPublicKeys)
}
}
getPublicKeys(condition.details)
return {
condition,
amount,
public_keys: publicKeys,
}
}
/**
* Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
* @param {string} preimage Preimage to be hashed and wrapped in a crypto-condition
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
*/
static makeSha256Condition(preimage, json = true) {
const sha256Fulfillment = new PreimageSha256()
sha256Fulfillment.setPreimage(Buffer.from(preimage))
return json ? ccJsonify(sha256Fulfillment) : sha256Fulfillment
}
/**
* Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
* @param {number} threshold
* @param {Array} [subconditions=[]]
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
*/
static makeThresholdCondition(threshold, subconditions = [], json = true) {
const thresholdCondition = new ThresholdSha256()
thresholdCondition.setThreshold(threshold)
subconditions.forEach((subcondition) => {
// TODO: add support for Condition
thresholdCondition.addSubfulfillment(subcondition)
// ? Should be thresholdCondition.addSubcondition(subcondition)
})
return json ? ccJsonify(thresholdCondition) : thresholdCondition
}
/**
* Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
* the `fulfilledOutputs` of `unspentTransaction`.
* @param {Object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
* its Output Condition)
* @param {Object} metadata Metadata for the Transaction
* @param {Object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.
* For `TRANSFER` Transactions, this should usually just be a list of
* Outputs wrapping Ed25519 Conditions generated from the public keys of
* the recipients.
* @param {...number} OutputIndices Indices of the Outputs in `unspentTransaction` that this
* Transaction fulfills.
* Note that listed public keys listed must be used (and in
* the same order) to sign the Transaction
* (`signTransaction()`).
* @returns {Object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!
*/
// TODO:
// - Make `metadata` optional argument
static makeTransferTransaction(
unspentOutputs,
outputs,
metadata
) {
const inputs = unspentOutputs.map((unspentOutput) => {
const { tx, outputIndex } = { tx: unspentOutput.tx, outputIndex: unspentOutput.output_index }
const fulfilledOutput = tx.outputs[outputIndex]
const transactionLink = {
output_index: outputIndex,
transaction_id: tx.id,
}
return Transaction.makeInputTemplate(fulfilledOutput.public_keys, transactionLink)
})
const assetLink = {
id: unspentOutputs[0].tx.operation === 'CREATE' ? unspentOutputs[0].tx.id
: unspentOutputs[0].tx.asset.id
}
return Transaction.makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
}
/**
* Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
* that's been signed.
* Note: Only generates Ed25519 Fulfillments. Thresholds and other types of Fulfillments are left as
* an exercise for the user.
* @param {Object} transaction Transaction to sign. `transaction` is not modified.
* @param {...string} privateKeys Private keys associated with the issuers of the `transaction`.
* Looped through to iteratively sign any Input Fulfillments found in
* the `transaction`.
* @returns {Object} The signed version of `transaction`.
*/
static signTransaction(transaction, ...privateKeys) {
const signedTx = clone(transaction)
const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(transaction)
signedTx.inputs.forEach((input, index) => {
const privateKey = privateKeys[index]
const privateKeyBuffer = base58.decode(privateKey)
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
.concat(input.fulfills.transaction_id)
.concat(input.fulfills.output_index) : serializedTransaction
const transactionHash = sha256Hash(transactionUniqueFulfillment)
const ed25519Fulfillment = new Ed25519Sha256()
ed25519Fulfillment.sign(Buffer.from(transactionHash, 'hex'), privateKeyBuffer)
const fulfillmentUri = ed25519Fulfillment.serializeUri()
input.fulfillment = fulfillmentUri
})
const serializedSignedTransaction =
Transaction.serializeTransactionIntoCanonicalString(signedTx)
signedTx.id = sha256Hash(serializedSignedTransaction)
return signedTx
}
/**
* Delegate signing of the given `transaction` returning a new copy of `transaction`
* that's been signed.
* @param {Object} transaction Transaction to sign. `transaction` is not modified.
* @param {Function} signFn Function signing the transaction, expected to return the fulfillment.
* @returns {Object} The signed version of `transaction`.
*/
static delegateSignTransaction(transaction, signFn) {
const signedTx = clone(transaction)
const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(transaction)
signedTx.inputs.forEach((input, index) => {
const fulfillmentUri = signFn(serializedTransaction, input, index)
input.fulfillment = fulfillmentUri
})
const serializedSignedTransaction = Transaction.serializeTransactionIntoCanonicalString(signedTx)
signedTx.id = sha256Hash(serializedSignedTransaction)
return signedTx
}
/**
* Delegate signing of the given `transaction` returning a new copy of `transaction`
* that's been signed.
* @param {Object} transaction Transaction to sign. `transaction` is not modified.
* @param {Function} signFn Function signing the transaction, expected to resolve the fulfillment.
* @returns {Promise<Object>} The signed version of `transaction`.
*/
static async delegateSignTransactionAsync(transaction, signFn) {
const signedTx = clone(transaction)
const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(transaction)
await Promise.all(signedTx.inputs.map(async (input, index) => {
const fulfillmentUri = await signFn(serializedTransaction, input, index)
input.fulfillment = fulfillmentUri
}))
const serializedSignedTransaction = Transaction.serializeTransactionIntoCanonicalString(signedTx)
signedTx.id = sha256Hash(serializedSignedTransaction)
return signedTx
}
}

View File

@ -1,10 +0,0 @@
import serializeTransactionIntoCanonicalString from './serializeTransactionIntoCanonicalString'
import sha256Hash from '../sha256Hash'
export default function hashTransaction(transaction) {
// Safely remove any tx id from the given transaction for hashing
const tx = { ...transaction }
delete tx.id
return sha256Hash(serializeTransactionIntoCanonicalString(tx))
}

View File

@ -1,11 +0,0 @@
export makeEd25519Condition from './makeEd25519Condition'
export makeSha256Condition from './makeSha256Condition'
export makeThresholdCondition from './makeThresholdCondition'
export makeCreateTransaction from './makeCreateTransaction'
export makeOutput from './makeOutput'
export makeTransaction from './makeTransaction'
export makeTransferTransaction from './makeTransferTransaction'
export serializeTransactionIntoCanonicalString from './serializeTransactionIntoCanonicalString'
export signTransaction from './signTransaction'
export ccJsonLoad from './utils/ccJsonLoad'
export ccJsonify from './utils/ccJsonify'

View File

@ -1,31 +0,0 @@
import makeInputTemplate from './makeInputTemplate'
import makeTransaction from './makeTransaction'
/**
* @public
* Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
* the `issuers`.
* @param {object} asset Created asset's data
* @param {object} metadata Metadata for the Transaction
* @param {object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.
* For `CREATE` Transactions, this should usually just be a list of
* Outputs wrapping Ed25519 Conditions generated from the issuers' public
* keys (so that the issuers are the recipients of the created asset).
* @param {...string[]} issuers Public key of one or more issuers to the asset being created by this
* Transaction.
* Note: Each of the private keys corresponding to the given public
* keys MUST be used later (and in the same order) when signing the
* Transaction (`signTransaction()`).
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!
*/
export default function makeCreateTransaction(asset, metadata, outputs, ...issuers) {
const assetDefinition = {
'data': asset || null,
}
const inputs = issuers.map((issuer) => makeInputTemplate([issuer]))
return makeTransaction('CREATE', assetDefinition, metadata, outputs, inputs)
}

View File

@ -1,27 +0,0 @@
import { Buffer } from 'buffer'
import base58 from 'bs58'
import cc from 'five-bells-condition'
import ccJsonify from './utils/ccJsonify'
/**
* @public
* Create an Ed25519 Cryptocondition from an Ed25519 public key to put into an Output of a Transaction
* @param {string} publicKey base58 encoded Ed25519 public key for the recipient of the Transaction
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output)
*/
export default function makeEd25519Condition(publicKey, json = true) {
const publicKeyBuffer = new Buffer(base58.decode(publicKey))
const ed25519Fulfillment = new cc.Ed25519()
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
if (json) {
return ccJsonify(ed25519Fulfillment)
}
return ed25519Fulfillment
}

View File

@ -1,7 +0,0 @@
export default function makeInputTemplate(publicKeys = [], fulfills = null, fulfillment = null) {
return {
fulfillment,
fulfills,
'owners_before': publicKeys,
}
}

View File

@ -1,16 +0,0 @@
/**
* @public
* Create an Output from a Condition.
* Note: Assumes the given Condition was generated from a single public key (e.g. a Ed25519 Condition)
* @param {object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {number} amount Amount of the output
* @returns {object} An Output usable in a Transaction
*/
export default function makeOutput(condition, amount = 1) {
return {
'amount': amount,
condition,
'public_keys': condition.details.hasOwnProperty('public_key') ?
[condition.details.public_key] : [],
}
}

View File

@ -1,23 +0,0 @@
import { Buffer } from 'buffer'
import cc from 'five-bells-condition'
import ccJsonify from './utils/ccJsonify'
/**
* @public
* Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
* @param {string} preimage Preimage to be hashed and wrapped in a crypto-condition
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
*/
export default function makeSha256Condition(preimage, json = true) {
const sha256Fulfillment = new cc.PreimageSha256()
sha256Fulfillment.preimage = new Buffer(preimage)
if (json) {
return ccJsonify(sha256Fulfillment)
}
return sha256Fulfillment
}

View File

@ -1,28 +0,0 @@
import cc from 'five-bells-condition'
import ccJsonify from './utils/ccJsonify'
/**
* @public
* Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
* @param {number} threshold
* @param {Array} [subconditions=[]]
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Sha256 Threshold Condition (that will need to wrapped in an Output)
*/
export default function makeThresholdCondition(threshold, subconditions = [], json = true) {
const thresholdCondition = new cc.ThresholdSha256()
thresholdCondition.threshold = threshold
subconditions.forEach((subcondition) => {
// TODO: add support for Condition and URIs
thresholdCondition.addSubfulfillment(subcondition)
})
if (json) {
return ccJsonify(thresholdCondition)
}
return thresholdCondition
}

View File

@ -1,28 +0,0 @@
import hashTransaction from './hashTransaction'
function makeTransactionTemplate() {
return {
'id': null,
'operation': null,
'outputs': [],
'inputs': [],
'metadata': null,
'asset': null,
'version': '0.9',
}
}
export default function makeTransaction(operation, asset, metadata = null, outputs = [], inputs = []) {
const tx = makeTransactionTemplate()
tx.operation = operation
tx.asset = asset
tx.metadata = metadata
tx.inputs = inputs
tx.outputs = outputs
// Hashing must be done after, as the hash is of the Transaction (up to now)
tx.id = hashTransaction(tx)
return tx
}

View File

@ -1,47 +0,0 @@
import makeInputTemplate from './makeInputTemplate'
import makeTransaction from './makeTransaction'
/**
* @public
* Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
* the `fulfilledOutputs` of `unspentTransaction`.
* @param {object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
* its Output Condition)
* @param {object} metadata Metadata for the Transaction
* @param {object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.
* For `TRANSFER` Transactions, this should usually just be a list of
* Outputs wrapping Ed25519 Conditions generated from the public keys of
* the recipients.
* @param {...number} fulfilledOutputs Indices of the Outputs in `unspentTransaction` that this
* Transaction fulfills.
* Note that the public keys listed in the fulfilled Outputs
* must be used (and in the same order) to sign the Transaction
* (`signTransaction()`).
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!
*/
export default function makeTransferTransaction(
unspentTransaction,
metadata,
outputs,
...fulfilledOutputs
) {
const inputs = fulfilledOutputs.map((outputIndex) => {
const fulfilledOutput = unspentTransaction.outputs[outputIndex]
const transactionLink = {
'output': outputIndex,
'txid': unspentTransaction.id,
}
return makeInputTemplate(fulfilledOutput.public_keys, transactionLink)
})
const assetLink = {
'id': unspentTransaction.operation === 'CREATE' ? unspentTransaction.id
: unspentTransaction.asset.id
}
return makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
}

View File

@ -1,17 +0,0 @@
import stableStringify from 'json-stable-stringify'
import clone from 'clone'
/**
* @public
* Canonically serializes a transaction into a string by sorting the keys
* @param {object} (transaction)
* @return {string} a canonically serialized Transaction
*/
export default function serializeTransactionIntoCanonicalString(transaction) {
// BigchainDB signs fulfillments by serializing transactions into a "canonical" format where
const tx = clone(transaction)
// TODO: set fulfillments to null
// Sort the keys
return stableStringify(tx, (a, b) => (a.key > b.key ? 1 : -1))
}

View File

@ -1,35 +0,0 @@
import { Buffer } from 'buffer'
import base58 from 'bs58'
import cc from 'five-bells-condition'
import clone from 'clone'
import serializeTransactionIntoCanonicalString from './serializeTransactionIntoCanonicalString'
/**
* @public
* Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
* that's been signed.
* Note: Only generates Ed25519 Fulfillments. Thresholds and other types of Fulfillments are left as
* an exercise for the user.
* @param {object} transaction Transaction to sign. `transaction` is not modified.
* @param {...string} privateKeys Private keys associated with the issuers of the `transaction`.
* Looped through to iteratively sign any Input Fulfillments found in
* the `transaction`.
* @returns {object} The signed version of `transaction`.
*/
export default function signTransaction(transaction, ...privateKeys) {
const signedTx = clone(transaction)
signedTx.inputs.forEach((input, index) => {
const privateKey = privateKeys[index]
const privateKeyBuffer = new Buffer(base58.decode(privateKey))
const serializedTransaction = serializeTransactionIntoCanonicalString(transaction)
const ed25519Fulfillment = new cc.Ed25519()
ed25519Fulfillment.sign(new Buffer(serializedTransaction), privateKeyBuffer)
const fulfillmentUri = ed25519Fulfillment.serializeUri()
input.fulfillment = fulfillmentUri
})
return signedTx
}

View File

@ -1,49 +0,0 @@
import { Buffer } from 'buffer'
import base58 from 'bs58'
import cc from 'five-bells-condition'
/**
* @public
* Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
* @param {object} conditionJson
* @returns {cc.Condition} Ed25519 Condition (that will need to wrapped in an Output)
*/
export default function ccJsonLoad(conditionJson) {
if ('hash' in conditionJson) {
const condition = new cc.Condition()
condition.type = conditionJson.type_id
condition.bitmask = conditionJson.bitmask
condition.hash = new Buffer(base58.decode(conditionJson.hash))
condition.maxFulfillmentLength = parseInt(conditionJson.max_fulfillment_length, 10)
return condition
} else {
let fulfillment
if (conditionJson.type_id === 2) {
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)
}
})
}
if (conditionJson.type_id === 0) {
fulfillment = new cc.PreimageSha256()
fulfillment.preimage = new Buffer(conditionJson.preimage)
}
if (conditionJson.type_id === 4) {
fulfillment = new cc.Ed25519()
fulfillment.publicKey = new Buffer(base58.decode(conditionJson.public_key))
if (conditionJson.signature) {
fulfillment.signature = new Buffer(base58.decode(conditionJson.signature))
}
}
return fulfillment
}
}

64
src/transport.js Normal file
View File

@ -0,0 +1,64 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import Request from './request'
/**
*
* @private
* If initialized with ``>1`` nodes, the driver will send successive
* requests to different nodes in a round-robin fashion (this will be
* customizable in the future).
*/
export default class Transport {
constructor(nodes, timeout) {
this.connectionPool = []
this.timeout = timeout
// the maximum backoff time is 10 seconds
this.maxBackoffTime = timeout ? timeout / 2 : 10000
nodes.forEach(node => {
this.connectionPool.push(new Request(node))
})
}
// Select the connection with the earliest backoff time, in case of a tie,
// prefer the one with the smaller list index
pickConnection() {
let connection = this.connectionPool[0]
this.connectionPool.forEach(conn => {
// 0 the lowest value is the time for Thu Jan 01 1970 01:00:00 GMT+0100 (CET)
conn.backoffTime = conn.backoffTime ? conn.backoffTime : 0
connection = (conn.backoffTime < connection.backoffTime) ? conn : connection
})
return connection
}
async forwardRequest(path, headers) {
let response
let connection
// A new request will be executed until there is a valid response or timeout < 0
while (this.timeout >= 0) {
connection = this.pickConnection()
// Date in milliseconds
const startTime = Date.now()
// eslint-disable-next-line no-await-in-loop
response = await connection.request(
path,
headers,
this.timeout,
this.maxBackoffTime
)
const elapsed = Date.now() - startTime
if (connection.backoffTime > 0 && this.timeout > 0) {
this.timeout -= elapsed
} else {
// No connection error, the response is valid
return response
}
}
throw new Error('TimeoutError')
}
}

44
src/utils/ccJsonLoad.js Normal file
View File

@ -0,0 +1,44 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import base58 from 'bs58'
import { Condition, Ed25519Sha256, ThresholdSha256 } from 'crypto-conditions'
/**
* Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
* @param {Object} conditionJson
* @returns {cc.Condition} Ed25519 Condition (that will need to wrapped in an Output)
*/
export default function ccJsonLoad(conditionJson) {
if ('hash' in conditionJson) {
const condition = new Condition()
condition.setTypeId(conditionJson.type_id)
condition.setSubtypes(conditionJson.bitmask)
condition.setHash(base58.decode(conditionJson.hash))
// TODO: fix this, maxFulfillmentLength cannot be set in CryptoCondition lib
condition.maxFulfillmentLength = parseInt(conditionJson.max_fulfillment_length, 10)
return condition
} else {
let fulfillment
if (conditionJson.type === 'threshold-sha-256') {
fulfillment = new ThresholdSha256()
fulfillment.threshold = conditionJson.threshold
conditionJson.subconditions.forEach((subconditionJson) => {
const subcondition = ccJsonLoad(subconditionJson)
if ('getConditionUri' in subcondition) {
fulfillment.addSubfulfillment(subcondition)
} else if ('serializeUri' in subcondition) {
fulfillment.addSubcondition(subcondition)
}
})
}
if (conditionJson.type === 'ed25519-sha-256') {
fulfillment = new Ed25519Sha256()
fulfillment.setPublicKey(base58.decode(conditionJson.public_key))
}
return fulfillment
}
}

View File

@ -1,10 +1,13 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import base58 from 'bs58'
/**
* @public
* Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
* @param {cc.Fulfillment} fulfillment base58 encoded Ed25519 public key for recipient of the Transaction
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output)
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/
export default function ccJsonify(fulfillment) {
let conditionUri
@ -16,8 +19,8 @@ export default function ccJsonify(fulfillment) {
}
const jsonBody = {
'details': {},
'uri': conditionUri,
details: {},
uri: conditionUri,
}
if (fulfillment.getTypeId() === 0) {
@ -32,29 +35,23 @@ export default function ccJsonify(fulfillment) {
if (fulfillment.getTypeId() === 2) {
return {
'details': {
'type_id': 2,
'type': 'fulfillment',
'bitmask': fulfillment.getBitmask(),
'threshold': fulfillment.threshold,
'subfulfillments': fulfillment.subconditions.map((subcondition) => {
details: {
type: 'threshold-sha-256',
threshold: fulfillment.threshold,
subconditions: fulfillment.subconditions.map((subcondition) => {
const subconditionJson = ccJsonify(subcondition.body)
subconditionJson.details.weight = 1
return subconditionJson.details
})
},
'uri': conditionUri,
uri: conditionUri,
}
}
if (fulfillment.getTypeId() === 4) {
jsonBody.details.type_id = 4
jsonBody.details.bitmask = 32
jsonBody.details.type = 'ed25519-sha-256'
if ('publicKey' in fulfillment) {
jsonBody.details.signature = null
jsonBody.details.public_key = base58.encode(fulfillment.publicKey)
jsonBody.details.type = 'fulfillment'
}
}

View File

@ -0,0 +1,30 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import rewire from 'rewire'
const baseRequestFile = rewire('../../src/baseRequest.js')
const baseRequest = baseRequestFile.__get__('baseRequest')
const handleResponse = baseRequestFile.__get__('handleResponse')
test('HandleResponse does not throw error for response ok', t => {
const testObj = {
ok: true
}
const expected = testObj
const actual = handleResponse(testObj)
t.deepEqual(actual, expected)
})
test('baseRequest test query and vsprint', async t => {
const error = await t.throwsAsync(baseRequest('https://%s.com/', {
urlTemplateSpec: ['google'],
query: 'teapot'
}), { instanceOf: Error, message: 'HTTP Error: Requested page not reachable' })
t.is(error.requestURI, 'https://www.google.com/teapot')
t.is(error.status, '418 I\'m a Teapot')
})

View File

@ -0,0 +1,244 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import sinon from 'sinon'
import {
Connection
} from '../../src'
import {
API_PATH
} from '../constants'
const conn = new Connection(API_PATH)
test('Payload thrown at incorrect API_PATH', async t => {
const path = 'http://localhost:9984/api/wrong/'
const connection = new Connection(path)
const target = {
message: 'HTTP Error: Requested page not reachable',
status: '404 NOT FOUND',
requestURI: 'http://localhost:9984/api/wrong/transactions/transactionId'
}
const error = await t.throwsAsync(connection.getTransaction('transactionId'), {
instanceOf: Error, message: target.message
})
t.is('ResponseError', error.name)
t.is(target.status, error.status)
t.is(target.requestURI, error.requestURI)
})
test('Generate API URLS', t => {
const endpoints = {
'blocks': 'blocks',
'blocksDetail': 'blocks/%(blockHeight)s',
'outputs': 'outputs',
'transactions': 'transactions',
'transactionsSync': 'transactions?mode=sync',
'transactionsAsync': 'transactions?mode=async',
'transactionsCommit': 'transactions?mode=commit',
'transactionsDetail': 'transactions/%(transactionId)s',
'assets': 'assets',
}
Object.keys(endpoints).forEach(endpointName => {
const url = Connection.getApiUrls(endpointName)
const expected = endpoints[endpointName]
t.is(url, expected)
})
})
test('Normalize node from an object', t => {
const headers = {
custom: 'headers'
}
const node = {
endpoint: API_PATH,
headers: {
hello: 'world'
}
}
const expectedNode = {
'endpoint': API_PATH,
'headers': {
hello: 'world',
custom: 'headers'
}
}
t.deepEqual(Connection.normalizeNode(node, headers), expectedNode)
})
test('Normalize node from a string', t => {
const headers = {
custom: 'headers'
}
const expectedNode = {
'endpoint': API_PATH,
'headers': {
custom: 'headers'
}
}
t.deepEqual(Connection.normalizeNode(API_PATH, headers), expectedNode)
})
test('Request with custom headers', t => {
const testConn = new Connection(API_PATH, {
hello: 'world'
})
const expectedOptions = {
headers: {
custom: 'headers'
}
}
const PATH = 'blocks'
testConn.transport.forwardRequest = sinon.spy()
testConn._req(PATH, {
headers: {
custom: 'headers'
}
})
t.truthy(testConn.transport.forwardRequest.calledWith(PATH, expectedOptions))
})
test('Get block for a block id', t => {
const expectedPath = 'path'
const blockHeight = 'abc'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.getBlock(blockHeight)
t.truthy(conn._req.calledWith(
expectedPath,
{ urlTemplateSpec: { blockHeight } }
))
})
test('Get transaction for a transaction id', t => {
const expectedPath = 'path'
const transactionId = 'abc'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.getTransaction(transactionId)
t.truthy(conn._req.calledWith(
expectedPath,
{ urlTemplateSpec: { transactionId } }
))
})
test('Get list of blocks for a transaction id', t => {
const expectedPath = 'path'
const transactionId = 'abc'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.listBlocks(transactionId)
t.truthy(conn._req.calledWith(
expectedPath,
{
query: {
transaction_id: transactionId,
}
}
))
})
test('Get list of transactions for an asset id', t => {
const expectedPath = 'path'
const assetId = 'abc'
const operation = 'operation'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.listTransactions(assetId, operation)
t.truthy(conn._req.calledWith(
expectedPath,
{
query: {
asset_id: assetId,
operation
}
}
))
})
test('Get outputs for a public key and no spent flag', t => {
const expectedPath = 'path'
const publicKey = 'publicKey'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.listOutputs(publicKey)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { public_key: publicKey } }
))
})
test('Get outputs for a public key and spent=false', t => {
const expectedPath = 'path'
const publicKey = 'publicKey'
const spent = false
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.listOutputs(publicKey, spent)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { public_key: publicKey, spent: 'false' } }
))
})
test('Get outputs for a public key and spent=true', t => {
const expectedPath = 'path'
const publicKey = 'publicKey'
const spent = true
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.listOutputs(publicKey, spent)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { public_key: publicKey, spent: 'true' } }
))
})
test('Get asset for text', t => {
const expectedPath = 'path'
const search = 'abc'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.searchAssets(search)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { search, limit: 10 } }
))
})
test('Get metadata for text', t => {
const expectedPath = 'path'
const search = 'abc'
conn._req = sinon.spy()
Connection.getApiUrls = sinon.stub().returns(expectedPath)
conn.searchMetadata(search)
t.truthy(conn._req.calledWith(
expectedPath,
{ query: { search, limit: 10 } }
))
})

53
test/constants.js Normal file
View File

@ -0,0 +1,53 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import { createHash } from 'crypto'
import base58 from 'bs58'
import { Ed25519Sha256 } from 'crypto-conditions'
import { Transaction, Ed25519Keypair } from '../src'
// TODO: Find out if ava has something like conftest, if so put this there.
// NOTE: It's safer to cast `Math.random()` to a string, to avoid differences
// in "float interpretation" between languages (e.g. JavaScript and Python)
export const API_PATH = 'http://localhost:9984/api/v1/'
export function asset() { return { message: `${Math.random()}` } }
export const metaData = { message: 'metaDataMessage' }
export const alice = new Ed25519Keypair()
export const aliceCondition = Transaction.makeEd25519Condition(alice.publicKey)
export const aliceOutput = Transaction.makeOutput(aliceCondition)
export const createTx = Transaction.makeCreateTransaction(
asset,
metaData,
[aliceOutput],
alice.publicKey
)
export const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTx, output_index: 0 }],
[aliceOutput],
metaData
)
export const bob = new Ed25519Keypair()
export const bobCondition = Transaction.makeEd25519Condition(bob.publicKey)
export const bobOutput = Transaction.makeOutput(bobCondition)
export function delegatedSignTransaction(...keyPairs) {
return function sign(serializedTransaction, input) {
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
.concat(input.fulfills.transaction_id)
.concat(input.fulfills.output_index) : serializedTransaction
const transactionHash = createHash('sha3-256').update(transactionUniqueFulfillment).digest()
const filteredKeyPairs = keyPairs.filter(
({ publicKey }) => input.owners_before.includes(publicKey)
)
const ed25519Fulfillment = new Ed25519Sha256()
filteredKeyPairs.forEach(keyPair => {
const privateKey = Buffer.from(base58.decode(keyPair.privateKey))
ed25519Fulfillment.sign(transactionHash, privateKey)
})
return ed25519Fulfillment.serializeUri()
}
}

View File

@ -0,0 +1,455 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import { Ed25519Keypair, Transaction, Connection } from '../../src'
import {
API_PATH,
alice,
aliceCondition,
aliceOutput,
bob,
bobOutput,
asset,
metaData,
delegatedSignTransaction
} from '../constants'
test('Keypair is created', t => {
const keyPair = new Ed25519Keypair()
t.truthy(keyPair.publicKey)
t.truthy(keyPair.privateKey)
})
test('Valid CREATE transaction with default node', t => {
const conn = new Connection()
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
return conn.postTransaction(txSigned)
.then(resTx => {
t.truthy(resTx)
})
})
test('Valid CREATE transaction using async', t => {
const conn = new Connection(API_PATH)
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
return conn.postTransactionAsync(txSigned)
.then(resTx => t.truthy(resTx))
})
test('Valid CREATE transaction using sync', t => {
const conn = new Connection(API_PATH)
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
return conn.postTransactionSync(txSigned)
.then(resTx => t.truthy(resTx))
})
test('Valid TRANSFER transaction with single Ed25519 input', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(() => {
const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }],
[aliceOutput],
metaData
)
const transferTxSigned = Transaction.signTransaction(
transferTx,
alice.privateKey
)
return conn.postTransactionCommit(transferTxSigned)
.then(resTx => t.truthy(resTx))
})
})
test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput, bobOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(() => {
const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }, { tx: createTxSigned, output_index: 1 }],
[Transaction.makeOutput(aliceCondition, '2')],
metaData
)
const transferTxSigned = Transaction.signTransaction(
transferTx,
alice.privateKey,
bob.privateKey
)
return conn.postTransactionCommit(transferTxSigned)
.then(resTx => t.truthy(resTx))
})
})
test('Valid TRANSFER transaction with multiple Ed25519 inputs from different transactions', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
const carolCondition = Transaction.makeEd25519Condition(carol.publicKey)
const carolOutput = Transaction.makeOutput(carolCondition)
const trent = new Ed25519Keypair()
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
const trentOutput = Transaction.makeOutput(trentCondition)
const eli = new Ed25519Keypair()
const eliCondition = Transaction.makeEd25519Condition(eli.publicKey)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput, bobOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(() => {
const transferTx1 = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }],
[carolOutput],
metaData
)
const transferTxSigned1 = Transaction.signTransaction(
transferTx1,
alice.privateKey
)
const transferTx2 = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 1 }],
[trentOutput],
metaData
)
const transferTxSigned2 = Transaction.signTransaction(
transferTx2,
bob.privateKey
)
return conn.postTransactionCommit(transferTxSigned1)
.then(() => conn.postTransactionCommit(transferTxSigned2))
.then(() => {
const transferTxMultipleInputs = Transaction.makeTransferTransaction(
[{ tx: transferTxSigned1, output_index: 0 },
{ tx: transferTxSigned2, output_index: 0 }],
[Transaction.makeOutput(eliCondition, '2')],
metaData
)
const transferTxSignedMultipleInputs = Transaction.signTransaction(
transferTxMultipleInputs,
carol.privateKey,
trent.privateKey
)
return conn.postTransactionCommit(transferTxSignedMultipleInputs)
.then(resTx => t.truthy(resTx))
})
})
})
test('Valid CREATE transaction using delegateSign with default node', t => {
const conn = new Connection()
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const txSigned = Transaction.delegateSignTransaction(
tx,
delegatedSignTransaction(alice)
)
return conn.postTransaction(txSigned)
.then(resTx => {
t.truthy(resTx)
})
})
test('Valid TRANSFER transaction with multiple Ed25519 inputs using delegateSign', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput, bobOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(() => {
const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }, { tx: createTxSigned, output_index: 1 }],
[Transaction.makeOutput(aliceCondition, '2')],
metaData
)
const transferTxSigned = Transaction.delegateSignTransaction(
transferTx,
delegatedSignTransaction(alice, bob)
)
return conn.postTransactionCommit(transferTxSigned)
.then(resTx => t.truthy(resTx))
})
})
test('Search for spent and unspent outputs of a given public key', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
const carolCondition = Transaction.makeEd25519Condition(carol.publicKey)
const carolOutput = Transaction.makeOutput(carolCondition)
const trent = new Ed25519Keypair()
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
const trentOutput = Transaction.makeOutput(trentCondition)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[carolOutput, carolOutput],
carol.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
carol.privateKey,
carol.privateKey
)
// We spent output 1 (of 0, 1)
const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 1 }],
[trentOutput],
metaData
)
const transferTxSigned = Transaction.signTransaction(
transferTx,
carol.privateKey,
)
return conn.postTransactionCommit(createTxSigned)
.then(() => conn.postTransactionCommit(transferTxSigned))
.then(() => conn.listOutputs(carol.publicKey))
// now listOutputs should return us outputs 0 and 1 (unfiltered)
.then(outputs => t.truthy(outputs.length === 2))
})
test('Search for unspent outputs for a given public key', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
const carolCondition = Transaction.makeEd25519Condition(carol.publicKey)
const carolOutput = Transaction.makeOutput(carolCondition)
const trent = new Ed25519Keypair()
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
const trentOutput = Transaction.makeOutput(trentCondition)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[carolOutput, carolOutput, carolOutput],
carol.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
carol.privateKey,
carol.privateKey
)
// We spent output 1 (of 0, 1, 2)
const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 1 }],
[trentOutput],
metaData
)
const transferTxSigned = Transaction.signTransaction(
transferTx,
carol.privateKey,
)
return conn.postTransactionCommit(createTxSigned)
.then(() => conn.postTransactionCommit(transferTxSigned))
// now listOutputs should return us outputs 0 and 2 (1 is spent)
.then(() => conn.listOutputs(carol.publicKey, 'false'))
.then(outputs => t.truthy(outputs.length === 2))
})
test('Search for spent outputs for a given public key', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
const carolCondition = Transaction.makeEd25519Condition(carol.publicKey)
const carolOutput = Transaction.makeOutput(carolCondition)
const trent = new Ed25519Keypair()
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
const trentOutput = Transaction.makeOutput(trentCondition)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[carolOutput, carolOutput, carolOutput],
carol.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
carol.privateKey,
carol.privateKey
)
// We spent output 1 (of 0, 1, 2)
const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 1 }],
[trentOutput],
metaData
)
const transferTxSigned = Transaction.signTransaction(
transferTx,
carol.privateKey,
)
return conn.postTransactionCommit(createTxSigned)
.then(() => conn.postTransactionCommit(transferTxSigned))
// now listOutputs should only return us output 1 (0 and 2 are unspent)
.then(() => conn.listOutputs(carol.publicKey, true))
.then(outputs => t.truthy(outputs.length === 1))
})
test('Search for an asset', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(() => conn.searchAssets(createTxSigned.asset.data.message))
.then(assets => t.truthy(
assets.pop(),
createTxSigned.asset.data.message
))
})
test('Search for metadata', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(() => conn.searchMetadata(createTxSigned.metadata.message))
.then(assets => t.truthy(
assets.pop(),
createTxSigned.metadata.message
))
})
test('Search blocks containing a transaction', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(({ id }) => conn.listBlocks(id))
.then(blockHeight => conn.getBlock(blockHeight.pop()))
.then(({ transactions }) => transactions.filter(({ id }) => id === createTxSigned.id))
.then(transactions => t.truthy(transactions.length === 1))
})
test('Search transaction containing an asset', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransactionCommit(createTxSigned)
.then(({ id }) => conn.listTransactions(id))
.then(transactions => {
t.truthy(transactions.length === 1)
})
})
test('Content-Type cannot be set', t => {
t.throws(() => new Connection(API_PATH, { 'Content-Type': 'application/json' }), {
instanceOf: Error
})
})

View File

@ -0,0 +1,26 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import Connection from '../../src/connection'
const conn = new Connection()
test('Ensure that BackoffTimedelta works properly', t => {
const req = conn.transport.pickConnection()
req.backoffTime = Date.now() + 50
const target = req.getBackoffTimedelta()
// The value should be close to 50
t.is(target > 45, true)
})
test('Ensure that updateBackoffTime throws and error on TimeoutError', async t => {
const req = conn.transport.pickConnection()
const errorMessage = 'TimeoutError'
req.connectionError = new Error(errorMessage)
t.throws(() => {
req.updateBackoffTime()
}, { instanceOf: Error, message: errorMessage })
})

View File

@ -0,0 +1,55 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import rewire from 'rewire'
const sanitize = rewire('../../src/sanitize.js')
const applyFilterOnObject = sanitize.__get__('applyFilterOnObject')
const filterFromObject = sanitize.__get__('filterFromObject')
test('Ensure that null filter returns same object', t => {
const expected = { 'testObj': 'test' }
const actual = applyFilterOnObject({ 'testObj': 'test' }, null)
t.deepEqual(actual, expected)
})
test('Ensure function filter with isInclusion true works properly', t => {
const testObj = [true, false, undefined, '', 0, null]
const expected = { 0: true }
const actual = filterFromObject(testObj, (val) => !!val, { isInclusion: true })
t.deepEqual(actual, expected)
})
test('Ensure function filter with isInclusion false works properly', t => {
const testObj = [false, true, 1, 10, 'this will be removed as it is truthy']
const expected = { 0: false }
const actual = filterFromObject(testObj, (val) => !!val, { isInclusion: false })
t.deepEqual(actual, expected)
})
test('Ensure array filter with isInclusion true works properly', t => {
const testObj = [true, false, undefined, '', 0, null]
const expected = { 0: true }
const actual = filterFromObject(testObj, [true], { isInclusion: true })
t.deepEqual(actual, expected)
})
test('Ensure array filter with isInclusion false works properly', t => {
const testObj = [false, true, 1, 10]
const expected = { 0: false }
const actual = filterFromObject(testObj, [true, 1, 10], { isInclusion: false })
t.deepEqual(actual, expected)
})
test('Ensure throws error when given invalid filter', t => {
t.throws(() => {
filterFromObject({}, 'lol')
}, { instanceOf: Error, message: 'The given filter is not an array or function. Filter aborted' })
})

View File

@ -1,30 +0,0 @@
import test from 'ava'
import { Ed25519Keypair, Transaction, Connection } from '../src'
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('Valid CREATE transaction is evaluated by BigchainDB', t => {
const alice = new Ed25519Keypair()
const asset = { name: 'Shmui', type: 'cat' }
const metadata = { dayOfTheWeek: 'Caturday' }
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

@ -0,0 +1,50 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import formatText from '../../src/format_text'
test('formatText test type 1', t => {
const expected = 'Hi there Dimi!'
const actual = formatText('Hi there ${dimi}!', { dimi: 'Dimi' }) // eslint-disable-line no-template-curly-in-string
t.is(actual, expected)
})
test('formatText test type 2', t => {
const expected = 'BigchainDB is big'
const actual = formatText('${database} is %(status)s', { // eslint-disable-line no-template-curly-in-string
database: 'BigchainDB',
status: 'big'
})
t.is(actual, expected)
})
test('formatText test type 3', t => {
const expected = 'Berlin is best known for its Currywurst'
const actual = formatText(
'Berlin is best known for its ${berlin.topKnownFor[0].name}', // eslint-disable-line no-template-curly-in-string
{
berlin: {
topKnownFor: [
{
name: 'Currywurst'
}
]
}
}
)
t.is(actual, expected)
})
test('formatText test throws', t => {
t.throws(() => {
formatText(
'This will give ${error.}', // eslint-disable-line no-template-curly-in-string
{ error: [{}] }
)
}, { instanceOf: SyntaxError, message: '[formatText] failed to parse named argument key: error.' })
})

View File

@ -0,0 +1,151 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import { createHash } from 'crypto'
import { validateFulfillment } from 'crypto-conditions'
import test from 'ava'
import base58 from 'bs58'
import { Ed25519Keypair, Transaction, ccJsonLoad } from '../../src'
import { delegatedSignTransaction } from '../constants'
import sha256Hash from '../../src/sha256Hash'
test('Ed25519 condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const target = {
details: {
type: 'ed25519-sha-256',
public_key: publicKey,
},
uri: 'ni:///sha-256;uLdVX7FEjLWVDkAkfMAkEqPPwFqZj7qfiGE152t_x5c?fpt=ed25519-sha-256&cost=131072'
}
t.deepEqual(target, Transaction.makeEd25519Condition(publicKey))
})
test('Sha256Condition fulfillment', t => {
const preimage = 'secret'
const target = {
details: {
type_id: 0,
bitmask: 3,
preimage,
type: 'fulfillment'
},
uri: 'ni:///sha-256;K7gNU3sdo-OL0wNhqoVWhr3g6s1xYv72ol_pe_Unols?fpt=preimage-sha-256&cost=6'
}
t.deepEqual(target, Transaction.makeSha256Condition(preimage))
})
test('Threshold condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
const condition = Transaction.makeThresholdCondition(1, [ed25519, ed25519])
const output = Transaction.makeOutput(condition)
const target = {
condition: {
details: {
type: 'threshold-sha-256',
threshold: 1,
subconditions: [
{
type: 'ed25519-sha-256',
public_key: publicKey,
},
{
type: 'ed25519-sha-256',
public_key: publicKey,
}
]
},
uri: 'ni:///sha-256;xTeBhQj7ae5Tym7cp83fwtkesQnhdwNwDEMIYwnf2g0?fpt=threshold-sha-256&cost=133120&subtypes=ed25519-sha-256',
},
amount: '1',
public_keys: [publicKey]
}
t.deepEqual(target, output)
})
test('Fulfillment correctly formed', t => {
const alice = new Ed25519Keypair()
const txCreate = Transaction.makeCreateTransaction(
{},
{},
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
alice.publicKey
)
// Sign in order to get the tx id, needed for the unique fulfillment in the transfer transaction
const signCreateTransaction = Transaction.signTransaction(txCreate, alice.privateKey)
const txTransfer = Transaction.makeTransferTransaction(
[{ tx: signCreateTransaction, output_index: 0 }],
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
{}
)
const txSigned = Transaction.signTransaction(txTransfer, alice.privateKey)
// Here reconstruct the fulfillment of the transfer transaction
// The tx is serialized, and extended with tx_id and output index, and then hashed into bytes
const msg = Transaction.serializeTransactionIntoCanonicalString(txTransfer)
const msgUniqueFulfillment = txTransfer.inputs[0].fulfills ? msg
.concat(txTransfer.inputs[0].fulfills.transaction_id)
.concat(txTransfer.inputs[0].fulfills.output_index) : msg
const msgHash = sha256Hash(msgUniqueFulfillment)
t.truthy(validateFulfillment(
txSigned.inputs[0].fulfillment,
txCreate.outputs[0].condition.uri,
Buffer.from(msgHash, 'hex')
))
})
test('Delegated signature is correct', t => {
const alice = new Ed25519Keypair()
const txCreate = Transaction.makeCreateTransaction(
{},
{},
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
alice.publicKey
)
const signCreateTransaction = Transaction.signTransaction(txCreate, alice.privateKey)
const delegatedSignCreateTransaction = Transaction.delegateSignTransaction(
txCreate,
delegatedSignTransaction(alice)
)
t.deepEqual(signCreateTransaction, delegatedSignCreateTransaction)
})
test('Delegated async signature is correct', async t => {
const alice = new Ed25519Keypair()
const txCreate = Transaction.makeCreateTransaction(
{},
{},
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
alice.publicKey
)
const signCreateTransaction = Transaction.signTransaction(txCreate, alice.privateKey)
const delegatedSignCreateTransaction = await Transaction.delegateSignTransactionAsync(
txCreate,
delegatedSignTransaction(alice)
)
t.deepEqual(signCreateTransaction, delegatedSignCreateTransaction)
})
test('CryptoConditions JSON load', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const cond = ccJsonLoad({
type: 'threshold-sha-256',
threshold: 1,
subconditions: [{
type: 'ed25519-sha-256',
public_key: publicKey
},
{
hash: base58.encode(createHash('sha256').update('a').digest())
}],
})
t.truthy(cond.subconditions.length === 2)
})

View File

@ -0,0 +1,115 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import sinon from 'sinon'
import { Transaction } from '../../src'
import {
alice,
aliceOutput,
metaData,
createTx,
transferTx
} from '../constants'
test('Create valid output with default amount', t => {
const condition = {
details: {
type: 'ed25519-sha-256',
public_key: 'abc'
}
}
const expected = {
amount: '1',
condition,
public_keys: ['abc']
}
const res = Transaction.makeOutput(condition)
t.deepEqual(res, expected)
})
test('Create valid output with custom amount', t => {
const condition = {
details: {
type: 'ed25519-sha-256',
public_key: 'abc'
}
}
const customAmount = '1337'
const expected = {
amount: customAmount,
condition,
public_keys: ['abc']
}
const res = Transaction.makeOutput(condition, customAmount)
t.deepEqual(res, expected)
})
test('Pass condition not based on public_keys to makeOutput', t => {
const condition = {
details: {
idea: 'just pretend this is e.g. a hashlock'
}
}
const expected = {
amount: '1',
condition,
public_keys: []
}
const res = Transaction.makeOutput(condition)
t.deepEqual(res, expected)
})
test('makeOutput throws TypeError with incorrect amount type', t => {
t.throws(() => Transaction.makeOutput({}, 1337), { instanceOf: TypeError })
})
test('Create TRANSFER transaction based on CREATE transaction', t => {
sinon.spy(Transaction, 'makeTransaction')
Transaction.makeTransferTransaction(
[{ tx: createTx, output_index: 0 }],
[aliceOutput],
metaData
)
const expected = [
'TRANSFER',
{ id: createTx.id },
metaData,
[aliceOutput],
[Transaction.makeInputTemplate(
[alice.publicKey],
{ output_index: 0, transaction_id: createTx.id }
)]
]
// NOTE: `src/transaction/makeTransaction` is `export default`, hence we
// can only mock `makeTransaction.default` with a hack:
// See: https://stackoverflow.com/a/33676328/1263876
t.truthy(Transaction.makeTransaction.calledWith(...expected))
Transaction.makeTransaction.restore()
})
test('Create TRANSFER transaction based on TRANSFER transaction', t => {
sinon.spy(Transaction, 'makeTransaction')
Transaction.makeTransferTransaction(
[{ tx: transferTx, output_index: 0 }],
[aliceOutput],
metaData
)
const expected = [
'TRANSFER',
{ id: transferTx.asset.id },
metaData,
[aliceOutput],
[Transaction.makeInputTemplate(
[alice.publicKey],
{ output_index: 0, transaction_id: transferTx.id }
)]
]
t.truthy(Transaction.makeTransaction.calledWith(...expected))
Transaction.makeTransaction.restore()
})

View File

@ -0,0 +1,23 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import test from 'ava'
import {
Connection
} from '../../src'
test('Pick connection with earliest backoff time', async t => {
const path1 = 'http://localhost:9984/api/v1/'
const path2 = 'http://localhostwrong:9984/api/v1/'
// Reverse order
const conn = new Connection([path2, path1])
// This will trigger the 'forwardRequest' so the correct connection will be taken
await conn.searchAssets('example')
const connection1 = conn.transport.connectionPool[1]
t.deepEqual(conn.transport.pickConnection(), connection1)
})

10
types/Ed25519Keypair.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
export default class Ed25519Keypair {
publicKey: string;
privateKey: string;
constructor(seed?: Buffer);
}

31
types/baseRequest.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
export interface RequestConfig {
headers?: Record<string, string | string[]>;
jsonBody?: Record<string, any>;
query?: Record<string, any>;
method?: 'GET' | ' POST' | 'PUT';
urlTemplateSpec?: any[] | Record<string, any>;
[key: string]: any;
}
export function ResponseError(
message: string,
status?: number,
requestURI?: string
): void;
declare function timeout<T = Response>(
ms: number,
promise: Promise<T>
): Promise<T>;
declare function handleResponse(res: Response): Response;
export default function baseRequest(
url: string,
config: RequestConfig,
requestTimeout?: number
): Promise<Response>;

179
types/connection.d.ts vendored Normal file
View File

@ -0,0 +1,179 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import type { RequestConfig } from './baseRequest';
import type { Node } from './request';
import type Transport from './transport';
import type {
CreateTransaction,
TransactionOperations,
TransferTransaction,
TransactionCommon,
} from './transaction';
declare const DEFAULT_NODE = 'http://localhost:9984/api/v1/';
declare const DEFAULT_TIMEOUT = 20000; // The default value is 20 seconds
export interface InputNode {
endpoint: string;
}
export type AssetResult = {
id: string;
data: Record<string, any>;
};
export type MetadataResult = {
id: string;
metadata: Record<string, any>;
};
export enum Endpoints {
blocks = 'blocks',
blocksDetail = 'blocksDetail',
outputs = 'outputs',
transactions = 'transactions',
transactionsSync = 'transactionsSync',
transactionsAsync = 'transactionsAsync',
transactionsCommit = 'transactionsCommit',
transactionsDetail = 'transactionsDetail',
assets = 'assets',
metadata = 'metadata',
}
export interface EndpointsUrl {
[Endpoints.blocks]: 'blocks';
[Endpoints.blocksDetail]: 'blocks/%(blockHeight)s';
[Endpoints.outputs]: 'outputs';
[Endpoints.transactions]: 'transactions';
[Endpoints.transactionsSync]: 'transactions?mode=sync';
[Endpoints.transactionsAsync]: 'transactions?mode=async';
[Endpoints.transactionsCommit]: 'transactions?mode=commit';
[Endpoints.transactionsDetail]: 'transactions/%(transactionId)s';
[Endpoints.assets]: 'assets';
[Endpoints.metadata]: 'metadata';
}
export interface EndpointsResponse<
O = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
> {
[Endpoints.blocks]: number[];
[Endpoints.blocksDetail]: {
height: number;
transactions: (CreateTransaction | TransferTransaction)[];
};
[Endpoints.outputs]: {
transaction_id: string;
output_index: number;
}[];
[Endpoints.transactions]: O extends TransactionOperations.CREATE
? CreateTransaction[]
: O extends TransactionOperations.TRANSFER
? TransferTransaction[]
: (CreateTransaction | TransferTransaction)[];
[Endpoints.transactionsSync]: O extends TransactionOperations.CREATE
? CreateTransaction<A, M>
: TransferTransaction<M>;
[Endpoints.transactionsAsync]: O extends TransactionOperations.CREATE
? CreateTransaction<A, M>
: TransferTransaction<M>;
[Endpoints.transactionsCommit]: O extends TransactionOperations.CREATE
? CreateTransaction<A, M>
: TransferTransaction<M>;
[Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE
? CreateTransaction<A, M>
: TransferTransaction<M>;
[Endpoints.assets]: AssetResult[];
[Endpoints.metadata]: MetadataResult[];
}
export default class Connection {
private transport: Transport;
private normalizedNodes: Node[];
private headers: Record<string, string | string[]>;
constructor(
nodes: string | InputNode | (string | InputNode)[],
headers?: Record<string, string | string[]>,
timeout?: number
);
static normalizeNode(
node: string | InputNode,
headers: Record<string, string | string[]>
): Node;
static getApiUrls<E extends keyof EndpointsUrl>(endpoint: E): EndpointsUrl[E];
private _req<E extends keyof EndpointsUrl, O = Record<string, any>>(
path: EndpointsUrl[E],
options: RequestConfig
): Promise<O>;
getBlock(
blockHeight: number | string
): Promise<EndpointsResponse[Endpoints.blocksDetail]>;
getTransaction<O = TransactionOperations.CREATE>(
transactionId: string
): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>;
listBlocks(
transactionId: string
): Promise<EndpointsResponse[Endpoints.blocks]>;
listOutputs(
publicKey: string,
spent?: boolean
): Promise<EndpointsResponse[Endpoints.outputs]>;
listTransactions(
assetId: string,
operation?: TransactionOperations
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;
postTransaction<
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
postTransactionSync<
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;
postTransactionAsync<
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;
postTransactionCommit<
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
searchAssets(
search: string,
limit?: number
): Promise<EndpointsResponse[Endpoints.assets]>;
searchMetadata(
search: string,
limit?: number
): Promise<EndpointsResponse[Endpoints.metadata]>;
}

39
types/index.d.ts vendored Normal file
View File

@ -0,0 +1,39 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import Ed25519Keypair from './Ed25519Keypair';
import Connection, {
Endpoints,
EndpointsResponse,
EndpointsUrl,
} from './connection';
import Transaction, {
CreateTransaction,
TransactionCommon,
TransactionCommonSigned,
TransactionInput,
TransactionOutput,
TransferTransaction,
TransactionUnspentOutput,
TransactionOperations,
} from './transaction';
import ccJsonLoad from './utils/ccJsonLoad';
import ccJsonify from './utils/ccJsonify';
export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction };
// Extras
export {
Endpoints,
EndpointsResponse,
EndpointsUrl,
CreateTransaction,
TransactionCommon,
TransactionCommonSigned,
TransactionInput,
TransactionOutput,
TransferTransaction,
TransactionUnspentOutput,
TransactionOperations,
};

32
types/request.d.ts vendored Normal file
View File

@ -0,0 +1,32 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import type { RequestConfig } from './baseRequest';
export interface Node {
endpoint: string;
headers: Record<string, string | string[]>;
}
export default class Request {
private node: Node;
private backoffTime: number;
private retries: number;
private connectionError?: Error;
constructor(node: Node);
request<O = Record<string, any>>(
urlPath: string,
config?: RequestConfig,
timeout?: number,
maxBackoffTime?: number
): Promise<O>;
updateBackoffTime(maxBackoffTime: number): void;
getBackoffTimedelta(): number;
static sleep(ms: number): void;
}

25
types/sanitize.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
declare type FilterFn = (val: any, key?: string) => void;
declare function filterFromObject<I = Record<string, any>>(
obj: I,
filter: Array<any> | FilterFn,
conf: { isInclusion?: boolean }
): Partial<I>;
declare function applyFilterOnObject<I = Record<string, any>>(
obj: I,
filterFn?: FilterFn
): Partial<I>;
declare function selectFromObject<I = Record<string, any>>(
obj: I,
filter: Array<any> | FilterFn
): Partial<I>;
export default function sanitize<I = Record<string, any>>(
obj: I
): Partial<I> | I;

236
types/transaction.d.ts vendored Normal file
View File

@ -0,0 +1,236 @@
import type {
Ed25519Sha256,
Fulfillment,
PreimageSha256,
ThresholdSha256,
} from 'crypto-conditions';
import {
Ed25519Sha256JSONCondition,
PreimageSha256JSONCondition,
ThresholdSha256JSONCondition,
} from './utils/ccJsonify';
export interface TransactionInput {
fulfillment: string;
fulfills: {
output_index: number;
transaction_id: string;
} | null;
owners_before: string[];
}
export interface TransactionOutput {
amount: string;
condition:
| PreimageSha256JSONCondition
| ThresholdSha256JSONCondition
| Ed25519Sha256JSONCondition;
public_keys: string[];
}
export enum TransactionOperations {
CREATE = 'CREATE',
TRANSFER = 'TRANSFER',
}
export interface TransactionCommon<
O extends TransactionOperations = TransactionOperations.CREATE,
A extends Record<string, any> = Record<string, unknown>,
M extends Record<string, any> = Record<string, unknown>
> {
id?: string;
inputs: TransactionInput[];
outputs: TransactionOutput[];
version: string;
metadata: M;
operation: O;
asset: TransactionAssetMap<O, A>;
}
export interface TransactionCommonSigned<
O extends TransactionOperations = TransactionOperations.CREATE,
A extends Record<string, any> = Record<string, unknown>,
M extends Record<string, any> = Record<string, unknown>
> extends Omit<TransactionCommon<O, A, M>, 'id'> {
id: string;
}
export type TransactionAssetMap<
Operation,
A extends Record<string, any>
> = Operation extends TransactionOperations.CREATE
? {
data: A;
}
: {
id: string;
};
export interface CreateTransaction<
A extends Record<string, any> = Record<string, unknown>,
M extends Record<string, any> = Record<string, unknown>
> extends TransactionCommon<TransactionOperations.CREATE, A, M> {
id: string;
asset: TransactionAssetMap<TransactionOperations.CREATE, A>;
operation: TransactionOperations.CREATE;
}
export interface TransferTransaction<
M extends Record<string, any> = Record<string, unknown>
> extends TransactionCommon<TransactionOperations.TRANSFER, any, M> {
id: string;
asset: TransactionAssetMap<TransactionOperations.TRANSFER, { id: string }>;
operation: TransactionOperations.TRANSFER;
}
export interface TransactionUnspentOutput {
tx: TransactionCommon;
output_index: number;
}
interface TxTemplate {
id: null;
operation: null;
outputs: [];
inputs: [];
metadata: null;
asset: null;
version: '2.0';
}
export type DelegateSignFunction = (
serializedTransaction: string,
input: TransactionInput,
index?: number
) => string;
export type DelegateSignFunctionAsync = (
serializedTransaction: string,
input: TransactionInput,
index?: number
) => Promise<string>;
export default class Transaction {
static serializeTransactionIntoCanonicalString<
O extends TransactionOperations = TransactionOperations
>(transaction: TransactionCommon<O>): string;
static serializeTransactionIntoCanonicalString(
transaction: CreateTransaction | TransferTransaction
): string;
static makeEd25519Condition(publicKey: string): Ed25519Sha256JSONCondition;
static makeEd25519Condition(
publicKey: string,
json: true
): Ed25519Sha256JSONCondition;
static makeEd25519Condition(publicKey: string, json: false): Ed25519Sha256;
static makeEd25519Condition(
publicKey: string,
json?: boolean
): Ed25519Sha256 | Ed25519Sha256JSONCondition;
static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
static makeSha256Condition(
preimage: string,
json: true
): PreimageSha256JSONCondition;
static makeSha256Condition(preimage: string, json: false): PreimageSha256;
static makeSha256Condition(
preimage: string,
json?: boolean
): PreimageSha256 | PreimageSha256JSONCondition;
static makeThresholdCondition(
threshold: number,
subconditions: (string | Fulfillment)[]
): ThresholdSha256JSONCondition;
static makeThresholdCondition(
threshold: number,
subconditions: (string | Fulfillment)[],
json: true
): ThresholdSha256JSONCondition;
static makeThresholdCondition(
threshold: number,
subconditions: (string | Fulfillment)[],
json: false
): ThresholdSha256;
static makeThresholdCondition(
threshold: number,
subconditions: (string | Fulfillment)[],
json?: boolean
): ThresholdSha256 | ThresholdSha256JSONCondition;
static makeInputTemplate(
publicKeys: string[],
fulfills?: TransactionInput['fulfills'],
fulfillment?: TransactionInput['fulfillment']
): TransactionInput;
static makeOutput(
condition:
| PreimageSha256JSONCondition
| ThresholdSha256JSONCondition
| Ed25519Sha256JSONCondition,
amount?: string
): TransactionOutput;
static makeTransactionTemplate(): TxTemplate;
static makeTransaction<
O extends TransactionOperations,
A = Record<string, any>,
M = Record<string, any>
>(
operation: O,
asset: A,
metadata: M,
outputs: TransactionOutput[],
inputs: TransactionInput[]
): TransactionCommon<O, A, M>;
static makeCreateTransaction<
A = Record<string, any>,
M = Record<string, any>
>(
asset: A,
metadata: M,
outputs: TransactionOutput[],
...issuers: string[]
): CreateTransaction<A, M>;
static makeTransferTransaction<M = Record<string, any>>(
unspentOutputs: TransactionUnspentOutput[],
outputs: TransactionOutput[],
metadata: M
): TransferTransaction<M>;
static signTransaction<
O extends TransactionOperations = TransactionOperations.CREATE
>(
transaction: TransactionCommon<O>,
...privateKeys: string[]
): TransactionCommonSigned<O>;
static delegateSignTransaction<
O extends TransactionOperations = TransactionOperations.CREATE
>(
transaction: TransactionCommon<O>,
signFn: DelegateSignFunction
): TransactionCommonSigned<O>;
static delegateSignTransactionAsync<
O extends TransactionOperations = TransactionOperations.CREATE
>(
transaction: TransactionCommon<O>,
signFn: DelegateSignFunctionAsync
): Promise<TransactionCommonSigned<O>>;
}

21
types/transport.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import Request, { Node } from './request';
import type { RequestConfig } from './baseRequest';
export default class Transport {
private connectionPool: Request[];
private timeout: number;
private maxBackoffTime: number;
constructor(nodes: Node[], timeout: number);
pickConnection(): Request;
forwardRequest<O = Record<string, any>>(
path: string,
config: RequestConfig
): Promise<O>;
}

32
types/utils/ccJsonLoad.d.ts vendored Normal file
View File

@ -0,0 +1,32 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import type {
Condition,
Ed25519Sha256,
PreimageSha256,
ThresholdSha256,
} from 'crypto-conditions';
import type {
Ed25519Sha256JSONCondition,
JSONCondition,
PreimageSha256JSONCondition,
ThresholdSha256JSONCondition,
} from './ccJsonify';
declare function ccJsonLoad(
conditionJson: PreimageSha256JSONCondition
): PreimageSha256;
declare function ccJsonLoad(
conditionJson: ThresholdSha256JSONCondition
): ThresholdSha256;
declare function ccJsonLoad(
conditionJson: Ed25519Sha256JSONCondition
): Ed25519Sha256;
declare function ccJsonLoad(conditionJson: JSONCondition): Condition;
export default ccJsonLoad;

70
types/utils/ccJsonify.d.ts vendored Normal file
View File

@ -0,0 +1,70 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import type {
Condition,
Ed25519Sha256,
PreimageSha256,
ThresholdSha256,
} from 'crypto-conditions';
import type { TypeId, TypeName } from 'crypto-conditions/types/types';
interface BaseJSONCondition {
details: {
[key: string]: any;
};
uri: string;
}
export interface JSONCondition extends BaseJSONCondition {
details: {
type_id: TypeId;
bitmask: number;
type: 'condition';
hash: string;
max_fulfillment_length: number;
};
}
export interface PreimageSha256JSONCondition extends BaseJSONCondition {
details: {
type_id: TypeId.PreimageSha256;
bitmask: 3;
preimage?: string;
type?: 'fulfillement';
};
}
export interface ThresholdSha256JSONCondition extends BaseJSONCondition {
details: {
type: TypeName.ThresholdSha256;
subConditions: (Ed25519Sha256JSONCondition | PreimageSha256JSONCondition)[];
};
}
export interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
}
export type JSONConditionUnion =
| JSONCondition
| PreimageSha256JSONCondition
| ThresholdSha256JSONCondition
| Ed25519Sha256JSONCondition;
declare function ccJsonify(
fulfillment: PreimageSha256
): PreimageSha256JSONCondition;
declare function ccJsonify(
fulfillment: ThresholdSha256
): ThresholdSha256JSONCondition;
declare function ccJsonify(
fulfillment: Ed25519Sha256
): Ed25519Sha256JSONCondition;
declare function ccJsonify(fulfillment: Condition): JSONCondition;
export default ccJsonify;

42
webpack.common.js Normal file
View File

@ -0,0 +1,42 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable strict, no-console, object-shorthand */
'use strict'
const { ProvidePlugin } = require('webpack')
const { paths } = require('./webpack.parts')
module.exports = {
entry: paths.entry,
mode: 'none',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
}
]
},
optimization: {
minimize: true,
emitOnErrors: false
},
resolve: {
extensions: ['.js'],
modules: ['node_modules'],
fallback: {
buffer: require.resolve('buffer/'),
}
},
plugins: [
new ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
]
}

View File

@ -1,80 +1,34 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable strict, no-console, object-shorthand */
'use strict'
const path = require('path')
const webpack = require('webpack')
const PRODUCTION = process.env.NODE_ENV === 'production'
const PATHS = {
ENTRY: path.resolve(__dirname, './src/index.js'),
BUNDLE: path.resolve(__dirname, 'dist/browser'),
NODE_MODULES: path.resolve(__dirname, 'node_modules'),
const common = require('./webpack.common')
const { outputs } = require('./webpack.parts')
// '[libraryTarget]': [file extension]
const OUTPUT_MAPPING = {
'amd': 'amd',
'commonjs': 'cjs',
'commonjs2': 'cjs2',
'umd': 'umd',
'window': 'window',
}
/** PLUGINS **/
const PLUGINS = [
new webpack.NoEmitOnErrorsPlugin(),
]
const PROD_PLUGINS = [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
},
sourceMap: true,
}),
new webpack.LoaderOptionsPlugin({
debug: false,
minimize: true,
}),
]
const OVERRIDES = {
// optimization: {
// minimize: false
// }
}
if (PRODUCTION) {
PLUGINS.push(...PROD_PLUGINS)
module.exports = outputs(common, 'production', OUTPUT_MAPPING, OVERRIDES)
} else {
module.exports = outputs(common, 'development', OUTPUT_MAPPING, OVERRIDES)
}
/** EXPORTED WEBPACK CONFIG **/
const config = {
entry: [PATHS.ENTRY],
output: {
filename: PRODUCTION ? 'bundle.min.js' : 'bundle.js',
library: 'js-bigchaindb-driver',
libraryTarget: 'umd',
path: PATHS.BUNDLE,
},
devtool: PRODUCTION ? '#source-map' : '#inline-source-map',
resolve: {
extensions: ['.js'],
modules: ['node_modules'], // Don't use absolute path here to allow recursive matching
},
plugins: PLUGINS,
module: {
rules: [
{
test: /\.js$/,
exclude: [PATHS.NODE_MODULES],
use: [{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
}],
},
],
},
}
module.exports = config

32
webpack.development.js Normal file
View File

@ -0,0 +1,32 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable strict, no-console, object-shorthand, import/no-extraneous-dependencies */
'use strict'
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
devtool: 'inline-source-map',
optimization: {
minimizer: [
new TerserPlugin({
test: /vendor/,
}),
new TerserPlugin({
test: /^((?!(vendor)).)*.js$/,
})
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
}

59
webpack.parts.js Normal file
View File

@ -0,0 +1,59 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable strict, no-console, object-shorthand, import/no-extraneous-dependencies */
'use strict'
const path = require('path')
const { merge } = require('webpack-merge')
const development = require('./webpack.development')
const production = require('./webpack.production')
const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
const paths = {
entry: path.resolve(__dirname, './src/index.js'),
bundle: path.resolve(__dirname, 'dist/browser'),
}
const outputs = (base, env, mapping, overrides) => {
const collection = []
const library = 'bigchaindb-driver'
const windowLibrary = 'BigchainDB'
let environment = development
let ext = 'js'
if (env === 'production') {
environment = production
ext = `min.${ext}`
}
Object.entries(mapping).forEach(([target, extension]) => {
const filename = `[name].${library}.${extension}.${ext}`
const compiled = {
output: {
filename: filename,
library: target === 'window' ? windowLibrary : library,
libraryTarget: target,
path: paths.bundle
},
plugins: [
new AddVendorsPlugin(`${library}.${extension}.${ext}`)
]
}
collection.push(merge(base, environment, compiled, overrides))
})
return collection
}
module.exports = {
outputs,
paths
}

11
webpack.production.js Normal file
View File

@ -0,0 +1,11 @@
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
/* eslint-disable strict, no-console, object-shorthand */
'use strict'
module.exports = {
devtool: 'source-map',
}