mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-06-17 01:53:18 +02:00
Compare commits
80 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
17d3a02cb3 | ||
|
f9a4675726 | ||
|
7a12ee7eb9 | ||
|
eee8da4b78 | ||
|
2f3b2dbca1 | ||
|
334a3f4d2d | ||
|
1864f6fbb4 | ||
|
2ffbe99a2b | ||
|
ae13da59b4 | ||
|
30c15b962b | ||
|
1ba488b28f | ||
|
fbc3d79d98 | ||
|
46599f5446 | ||
|
8c0c72622d | ||
|
c5fe1346b9 | ||
|
dc353ee5bc | ||
|
38819a5934 | ||
|
34289b0640 | ||
|
1f95bec2be | ||
|
7c1e8be400 | ||
|
6aeece49cb | ||
|
71a231a50a | ||
|
76c877c649 | ||
|
f020a35ea2 | ||
|
9b395c14a6 | ||
|
d29b9c2566 | ||
|
6aa5f0100c | ||
|
1779f6eef4 | ||
|
44dfc8f825 | ||
|
d5fd300cfc | ||
|
71fe66c1f5 | ||
|
af90b97460 | ||
|
b177ca0de4 | ||
|
858acf2693 | ||
|
d26f667feb | ||
|
c98cc8e499 | ||
|
2a104eb86b | ||
|
90a2cb2608 | ||
|
84bd4efe03 | ||
|
5f6bef65c5 | ||
|
cd5c529324 | ||
|
7fe904061a | ||
|
902885f7d1 | ||
|
abaa40b269 | ||
|
611624fd7a | ||
|
3d49a6755e | ||
|
978585d649 | ||
|
43c541d6d7 | ||
|
272e6d6ae0 | ||
|
736b2adc37 | ||
|
dc7634c9db | ||
|
42112acd3e | ||
|
656de69c64 | ||
|
597ac56f1f | ||
|
1b9bafa097 | ||
|
e3cca78886 | ||
|
23c3fa50ef | ||
|
551180bceb | ||
|
86d02c2f04 | ||
|
90466cf6ae | ||
|
cc3aa3fdd3 | ||
|
f5cd60e63d | ||
|
317bdd4d0f | ||
|
41ce1178c7 | ||
|
ba87737d97 | ||
|
d5894deec4 | ||
|
3c76d3bb21 | ||
|
1f27cd2300 | ||
|
57a3e89871 | ||
|
e76c6227f8 | ||
|
ad7763f76c | ||
|
b3909b0f04 | ||
|
f0df142efb | ||
|
6dbafa8fad | ||
|
344702200d | ||
|
a4d8ff531b | ||
|
54ecf63a82 | ||
|
f5c2e92c69 | ||
|
4b0d5c40b6 | ||
|
b2e4ef55bf |
39
.babelrc
39
.babelrc
|
@ -1,12 +1,29 @@
|
||||||
{
|
{
|
||||||
"presets": [
|
"presets": [
|
||||||
"env"
|
[
|
||||||
],
|
"@babel/preset-env",
|
||||||
"plugins": [
|
{
|
||||||
"transform-export-extensions",
|
"targets": [
|
||||||
"transform-object-assign",
|
"> 0.25%, not dead",
|
||||||
"transform-object-rest-spread",
|
"not IE 11",
|
||||||
["transform-runtime", { "polyfill": false, "regenerator": true }]
|
"maintained node versions"
|
||||||
],
|
]
|
||||||
"sourceMaps": true
|
}
|
||||||
}
|
]
|
||||||
|
],
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
coverage
|
coverage
|
||||||
|
media
|
||||||
|
docs
|
||||||
|
compose
|
231
.eslintrc.js
Normal file
231
.eslintrc.js
Normal 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],
|
||||||
|
},
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "ascribe"
|
|
||||||
}
|
|
68
.github/workflows/ci.yml
vendored
Normal file
68
.github/workflows/ci.yml
vendored
Normal 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
|
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
_
|
|
@ -10,9 +10,9 @@ services:
|
||||||
language: node_js
|
language: node_js
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- 8
|
|
||||||
- 9
|
|
||||||
- 10
|
- 10
|
||||||
|
- 12
|
||||||
|
- 14
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
|
@ -20,7 +20,7 @@ cache:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- DOCKER_COMPOSE_VERSION=1.19.0
|
- DOCKER_COMPOSE_VERSION=1.28.5
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- .ci/travis-before-install.sh
|
- .ci/travis-before-install.sh
|
||||||
|
|
317
API.md
317
API.md
|
@ -1,9 +1,3 @@
|
||||||
<!---
|
|
||||||
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
|
|
||||||
--->
|
|
||||||
|
|
||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
@ -23,71 +17,72 @@ Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
- [Parameters][13]
|
- [Parameters][13]
|
||||||
- [listTransactions][14]
|
- [listTransactions][14]
|
||||||
- [Parameters][15]
|
- [Parameters][15]
|
||||||
- [listVotes][16]
|
- [postTransaction][16]
|
||||||
- [Parameters][17]
|
- [Parameters][17]
|
||||||
- [postTransaction][18]
|
- [postTransactionSync][18]
|
||||||
- [Parameters][19]
|
- [Parameters][19]
|
||||||
- [postTransactionSync][20]
|
- [postTransactionAsync][20]
|
||||||
- [Parameters][21]
|
- [Parameters][21]
|
||||||
- [postTransactionAsync][22]
|
- [postTransactionCommit][22]
|
||||||
- [Parameters][23]
|
- [Parameters][23]
|
||||||
- [postTransactionCommit][24]
|
- [searchAssets][24]
|
||||||
- [Parameters][25]
|
- [Parameters][25]
|
||||||
- [searchAssets][26]
|
- [searchMetadata][26]
|
||||||
- [Parameters][27]
|
- [Parameters][27]
|
||||||
- [searchMetadata][28]
|
- [Transaction][28]
|
||||||
- [Parameters][29]
|
- [serializeTransactionIntoCanonicalString][29]
|
||||||
- [Transaction][30]
|
- [Parameters][30]
|
||||||
- [serializeTransactionIntoCanonicalString][31]
|
- [makeCreateTransaction][31]
|
||||||
- [Parameters][32]
|
- [Parameters][32]
|
||||||
- [makeCreateTransaction][33]
|
- [makeEd25519Condition][33]
|
||||||
- [Parameters][34]
|
- [Parameters][34]
|
||||||
- [makeEd25519Condition][35]
|
- [makeOutput][35]
|
||||||
- [Parameters][36]
|
- [Parameters][36]
|
||||||
- [makeOutput][37]
|
- [makeSha256Condition][37]
|
||||||
- [Parameters][38]
|
- [Parameters][38]
|
||||||
- [makeSha256Condition][39]
|
- [makeThresholdCondition][39]
|
||||||
- [Parameters][40]
|
- [Parameters][40]
|
||||||
- [makeThresholdCondition][41]
|
- [makeTransferTransaction][41]
|
||||||
- [Parameters][42]
|
- [Parameters][42]
|
||||||
- [makeTransferTransaction][43]
|
- [signTransaction][43]
|
||||||
- [Parameters][44]
|
- [Parameters][44]
|
||||||
- [signTransaction][45]
|
- [delegateSignTransaction][45]
|
||||||
- [Parameters][46]
|
- [Parameters][46]
|
||||||
- [ccJsonLoad][47]
|
- [delegateSignTransactionAsync][47]
|
||||||
- [Parameters][48]
|
- [Parameters][48]
|
||||||
- [ccJsonify][49]
|
- [ccJsonLoad][49]
|
||||||
- [Parameters][50]
|
- [Parameters][50]
|
||||||
|
- [ccJsonify][51]
|
||||||
|
- [Parameters][52]
|
||||||
|
|
||||||
## Ed25519Keypair
|
## Ed25519Keypair
|
||||||
|
|
||||||
[src/Ed25519Keypair.js:12-17][51]
|
[src/Ed25519Keypair.js:16-21][53]
|
||||||
|
|
||||||
Type: [Object][52]
|
Type: [Object][54]
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `seed` **[Buffer][53]?** A seed that will be used as a key derivation function
|
- `seed` **[Buffer][55]?** A seed that will be used as a key derivation function
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- `publicKey` **[string][54]**
|
- `publicKey` **[string][56]**
|
||||||
- `privateKey` **[string][54]**
|
- `privateKey` **[string][56]**
|
||||||
|
|
||||||
## Connection
|
## Connection
|
||||||
|
|
||||||
[src/connection.js:8-178][55]
|
[src/connection.js:21-199][57]
|
||||||
|
|
||||||
Base connection
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `path`
|
- `nodes`
|
||||||
- `headers` (optional, default `{}`)
|
- `headers` **[Object][54]** Common headers for every request (optional, default `{}`)
|
||||||
|
- `timeout` **float** Optional timeout in secs (optional, default `DEFAULT_TIMEOUT`)
|
||||||
|
|
||||||
### getBlock
|
### getBlock
|
||||||
|
|
||||||
[src/connection.js:45-51][56]
|
[src/connection.js:79-85][58]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -95,7 +90,7 @@ Base connection
|
||||||
|
|
||||||
### getTransaction
|
### getTransaction
|
||||||
|
|
||||||
[src/connection.js:56-62][57]
|
[src/connection.js:90-96][59]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -103,7 +98,7 @@ Base connection
|
||||||
|
|
||||||
### listBlocks
|
### listBlocks
|
||||||
|
|
||||||
[src/connection.js:68-74][58]
|
[src/connection.js:102-108][60]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -112,7 +107,7 @@ Base connection
|
||||||
|
|
||||||
### listOutputs
|
### listOutputs
|
||||||
|
|
||||||
[src/connection.js:80-92][59]
|
[src/connection.js:114-126][61]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -121,24 +116,16 @@ Base connection
|
||||||
|
|
||||||
### listTransactions
|
### listTransactions
|
||||||
|
|
||||||
[src/connection.js:98-105][60]
|
[src/connection.js:132-139][62]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `assetId`
|
- `assetId`
|
||||||
- `operation`
|
- `operation`
|
||||||
|
|
||||||
### listVotes
|
|
||||||
|
|
||||||
[src/connection.js:110-116][61]
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
- `blockId`
|
|
||||||
|
|
||||||
### postTransaction
|
### postTransaction
|
||||||
|
|
||||||
[src/connection.js:121-123][62]
|
[src/connection.js:144-146][63]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -146,7 +133,7 @@ Base connection
|
||||||
|
|
||||||
### postTransactionSync
|
### postTransactionSync
|
||||||
|
|
||||||
[src/connection.js:128-133][63]
|
[src/connection.js:151-156][64]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -154,7 +141,7 @@ Base connection
|
||||||
|
|
||||||
### postTransactionAsync
|
### postTransactionAsync
|
||||||
|
|
||||||
[src/connection.js:139-144][64]
|
[src/connection.js:161-166][65]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -162,7 +149,7 @@ Base connection
|
||||||
|
|
||||||
### postTransactionCommit
|
### postTransactionCommit
|
||||||
|
|
||||||
[src/connection.js:150-155][65]
|
[src/connection.js:171-176][66]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -170,7 +157,7 @@ Base connection
|
||||||
|
|
||||||
### searchAssets
|
### searchAssets
|
||||||
|
|
||||||
[src/connection.js:160-166][66]
|
[src/connection.js:181-187][67]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -178,7 +165,7 @@ Base connection
|
||||||
|
|
||||||
### searchMetadata
|
### searchMetadata
|
||||||
|
|
||||||
[src/connection.js:171-177][67]
|
[src/connection.js:192-198][68]
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
@ -186,65 +173,65 @@ Base connection
|
||||||
|
|
||||||
## Transaction
|
## Transaction
|
||||||
|
|
||||||
[src/transaction.js:12-254][68]
|
[src/transaction.js:16-288][69]
|
||||||
|
|
||||||
Construct Transactions
|
Construct Transactions
|
||||||
|
|
||||||
### serializeTransactionIntoCanonicalString
|
### serializeTransactionIntoCanonicalString
|
||||||
|
|
||||||
[src/transaction.js:18-25][69]
|
[src/transaction.js:22-29][70]
|
||||||
|
|
||||||
Canonically serializes a transaction into a string by sorting the keys
|
Canonically serializes a transaction into a string by sorting the keys
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `transaction`
|
- `transaction`
|
||||||
- `null` **[Object][52]** (transaction)
|
- `null` **[Object][54]** (transaction)
|
||||||
|
|
||||||
Returns **[string][54]** a canonically serialized Transaction
|
Returns **[string][56]** a canonically serialized Transaction
|
||||||
|
|
||||||
### makeCreateTransaction
|
### makeCreateTransaction
|
||||||
|
|
||||||
[src/transaction.js:76-83][70]
|
[src/transaction.js:80-87][71]
|
||||||
|
|
||||||
Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
|
Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
|
||||||
the `issuers`.
|
the `issuers`.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `asset` **[Object][52]** Created asset's data
|
- `asset` **[Object][54]** Created asset's data
|
||||||
- `metadata` **[Object][52]** Metadata for the Transaction
|
- `metadata` **[Object][54]** Metadata for the Transaction
|
||||||
- `outputs` **[Array][71]<[Object][52]>** Array of Output objects to add to the Transaction.
|
- `outputs` **[Array][72]<[Object][54]>** Array of Output objects to add to the Transaction.
|
||||||
Think of these as the recipients of the asset after 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
|
For `CREATE` Transactions, this should usually just be a list of
|
||||||
Outputs wrapping Ed25519 Conditions generated from the issuers' public
|
Outputs wrapping Ed25519 Conditions generated from the issuers' public
|
||||||
keys (so that the issuers are the recipients of the created asset).
|
keys (so that the issuers are the recipients of the created asset).
|
||||||
- `issuers` **...[Array][71]<[string][54]>** Public key of one or more issuers to the asset being created by this
|
- `issuers` **...[Array][72]<[string][56]>** Public key of one or more issuers to the asset being created by this
|
||||||
Transaction.
|
Transaction.
|
||||||
Note: Each of the private keys corresponding to the given public
|
Note: Each of the private keys corresponding to the given public
|
||||||
keys MUST be used later (and in the same order) when signing the
|
keys MUST be used later (and in the same order) when signing the
|
||||||
Transaction (`signTransaction()`).
|
Transaction (`signTransaction()`).
|
||||||
|
|
||||||
Returns **[Object][52]** 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!
|
sending it off!
|
||||||
|
|
||||||
### makeEd25519Condition
|
### makeEd25519Condition
|
||||||
|
|
||||||
[src/transaction.js:92-103][72]
|
[src/transaction.js:96-101][73]
|
||||||
|
|
||||||
Create an Ed25519 Cryptocondition from an Ed25519 public key
|
Create an Ed25519 Cryptocondition from an Ed25519 public key
|
||||||
to put into an Output of a Transaction
|
to put into an Output of a Transaction
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `publicKey` **[string][54]** base58 encoded Ed25519 public key for the recipient of the Transaction
|
- `publicKey` **[string][56]** base58 encoded Ed25519 public key for the recipient of the Transaction
|
||||||
- `json` **[boolean][73]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
|
- `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
|
||||||
|
|
||||||
Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Output)
|
Returns **[Object][54]** Ed25519 Condition (that will need to wrapped in an Output)
|
||||||
|
|
||||||
### makeOutput
|
### makeOutput
|
||||||
|
|
||||||
[src/transaction.js:113-133][74]
|
[src/transaction.js:111-131][75]
|
||||||
|
|
||||||
Create an Output from a Condition.
|
Create an Output from a Condition.
|
||||||
Note: Assumes the given Condition was generated from a
|
Note: Assumes the given Condition was generated from a
|
||||||
|
@ -252,41 +239,41 @@ single public key (e.g. a Ed25519 Condition)
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `condition` **[Object][52]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
|
- `condition` **[Object][54]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
|
||||||
- `amount` **[string][54]** Amount of the output (optional, default `'1'`)
|
- `amount` **[string][56]** Amount of the output (optional, default `'1'`)
|
||||||
|
|
||||||
Returns **[Object][52]** An Output usable in a Transaction
|
Returns **[Object][54]** An Output usable in a Transaction
|
||||||
|
|
||||||
### makeSha256Condition
|
### makeSha256Condition
|
||||||
|
|
||||||
[src/transaction.js:141-149][75]
|
[src/transaction.js:139-143][76]
|
||||||
|
|
||||||
Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
|
Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `preimage` **[string][54]** Preimage to be hashed and wrapped in a crypto-condition
|
- `preimage` **[string][56]** Preimage to be hashed and wrapped in a crypto-condition
|
||||||
- `json` **[boolean][73]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
|
- `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
|
||||||
|
|
||||||
Returns **[Object][52]** Preimage-Sha256 Condition (that will need to wrapped in an Output)
|
Returns **[Object][54]** Preimage-Sha256 Condition (that will need to wrapped in an Output)
|
||||||
|
|
||||||
### makeThresholdCondition
|
### makeThresholdCondition
|
||||||
|
|
||||||
[src/transaction.js:158-172][76]
|
[src/transaction.js:152-162][77]
|
||||||
|
|
||||||
Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
|
Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `threshold` **[number][77]**
|
- `threshold` **[number][78]**
|
||||||
- `subconditions` **[Array][71]** (optional, default `[]`)
|
- `subconditions` **[Array][72]** (optional, default `[]`)
|
||||||
- `json` **[boolean][73]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
|
- `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
|
||||||
|
|
||||||
Returns **[Object][52]** Sha256 Threshold Condition (that will need to wrapped in an Output)
|
Returns **[Object][54]** Sha256 Threshold Condition (that will need to wrapped in an Output)
|
||||||
|
|
||||||
### makeTransferTransaction
|
### makeTransferTransaction
|
||||||
|
|
||||||
[src/transaction.js:195-216][78]
|
[src/transaction.js:185-206][79]
|
||||||
|
|
||||||
Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
|
Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
|
||||||
the `fulfilledOutputs` of `unspentTransaction`.
|
the `fulfilledOutputs` of `unspentTransaction`.
|
||||||
|
@ -294,26 +281,26 @@ the `fulfilledOutputs` of `unspentTransaction`.
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `unspentOutputs`
|
- `unspentOutputs`
|
||||||
- `outputs` **[Array][71]<[Object][52]>** Array of Output objects to add to the Transaction.
|
- `outputs` **[Array][72]<[Object][54]>** Array of Output objects to add to the Transaction.
|
||||||
Think of these as the recipients of the asset after 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
|
For `TRANSFER` Transactions, this should usually just be a list of
|
||||||
Outputs wrapping Ed25519 Conditions generated from the public keys of
|
Outputs wrapping Ed25519 Conditions generated from the public keys of
|
||||||
the recipients.
|
the recipients.
|
||||||
- `metadata` **[Object][52]** Metadata for the Transaction
|
- `metadata` **[Object][54]** Metadata for the Transaction
|
||||||
- `unspentTransaction` **[Object][52]** Previous Transaction you have control over (i.e. can fulfill
|
- `unspentTransaction` **[Object][54]** Previous Transaction you have control over (i.e. can fulfill
|
||||||
its Output Condition)
|
its Output Condition)
|
||||||
- `OutputIndices` **...[number][77]** Indices of the Outputs in `unspentTransaction` that this
|
- `OutputIndices` **...[number][78]** Indices of the Outputs in `unspentTransaction` that this
|
||||||
Transaction fulfills.
|
Transaction fulfills.
|
||||||
Note that listed public keys listed must be used (and in
|
Note that listed public keys listed must be used (and in
|
||||||
the same order) to sign the Transaction
|
the same order) to sign the Transaction
|
||||||
(`signTransaction()`).
|
(`signTransaction()`).
|
||||||
|
|
||||||
Returns **[Object][52]** 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!
|
sending it off!
|
||||||
|
|
||||||
### signTransaction
|
### signTransaction
|
||||||
|
|
||||||
[src/transaction.js:229-253][79]
|
[src/transaction.js:219-243][80]
|
||||||
|
|
||||||
Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
|
Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
|
||||||
that's been signed.
|
that's been signed.
|
||||||
|
@ -322,28 +309,56 @@ an exercise for the user.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `transaction` **[Object][52]** Transaction to sign. `transaction` is not modified.
|
- `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
|
||||||
- `privateKeys` **...[string][54]** Private keys associated with the issuers of the `transaction`.
|
- `privateKeys` **...[string][56]** Private keys associated with the issuers of the `transaction`.
|
||||||
Looped through to iteratively sign any Input Fulfillments found in
|
Looped through to iteratively sign any Input Fulfillments found in
|
||||||
the `transaction`.
|
the `transaction`.
|
||||||
|
|
||||||
Returns **[Object][52]** 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]<[Object][54]>** The signed version of `transaction`.
|
||||||
|
|
||||||
## ccJsonLoad
|
## ccJsonLoad
|
||||||
|
|
||||||
[src/utils/ccJsonLoad.js:10-40][80]
|
[src/utils/ccJsonLoad.js:13-44][85]
|
||||||
|
|
||||||
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
|
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `conditionJson` **[Object][52]**
|
- `conditionJson` **[Object][54]**
|
||||||
|
|
||||||
Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)
|
Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)
|
||||||
|
|
||||||
## ccJsonify
|
## ccJsonify
|
||||||
|
|
||||||
[src/utils/ccJsonify.js:8-61][81]
|
[src/utils/ccJsonify.js:12-65][86]
|
||||||
|
|
||||||
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
|
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
|
||||||
|
|
||||||
|
@ -351,7 +366,7 @@ Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB
|
||||||
|
|
||||||
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
|
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
|
||||||
|
|
||||||
Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Output)
|
Returns **[Object][54]** Ed25519 Condition (that will need to wrapped in an Output)
|
||||||
|
|
||||||
[1]: #ed25519keypair
|
[1]: #ed25519keypair
|
||||||
|
|
||||||
|
@ -383,134 +398,144 @@ Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Outp
|
||||||
|
|
||||||
[15]: #parameters-6
|
[15]: #parameters-6
|
||||||
|
|
||||||
[16]: #listvotes
|
[16]: #posttransaction
|
||||||
|
|
||||||
[17]: #parameters-7
|
[17]: #parameters-7
|
||||||
|
|
||||||
[18]: #posttransaction
|
[18]: #posttransactionsync
|
||||||
|
|
||||||
[19]: #parameters-8
|
[19]: #parameters-8
|
||||||
|
|
||||||
[20]: #posttransactionsync
|
[20]: #posttransactionasync
|
||||||
|
|
||||||
[21]: #parameters-9
|
[21]: #parameters-9
|
||||||
|
|
||||||
[22]: #posttransactionasync
|
[22]: #posttransactioncommit
|
||||||
|
|
||||||
[23]: #parameters-10
|
[23]: #parameters-10
|
||||||
|
|
||||||
[24]: #posttransactioncommit
|
[24]: #searchassets
|
||||||
|
|
||||||
[25]: #parameters-11
|
[25]: #parameters-11
|
||||||
|
|
||||||
[26]: #searchassets
|
[26]: #searchmetadata
|
||||||
|
|
||||||
[27]: #parameters-12
|
[27]: #parameters-12
|
||||||
|
|
||||||
[28]: #searchmetadata
|
[28]: #transaction
|
||||||
|
|
||||||
[29]: #parameters-13
|
[29]: #serializetransactionintocanonicalstring
|
||||||
|
|
||||||
[30]: #transaction
|
[30]: #parameters-13
|
||||||
|
|
||||||
[31]: #serializetransactionintocanonicalstring
|
[31]: #makecreatetransaction
|
||||||
|
|
||||||
[32]: #parameters-14
|
[32]: #parameters-14
|
||||||
|
|
||||||
[33]: #makecreatetransaction
|
[33]: #makeed25519condition
|
||||||
|
|
||||||
[34]: #parameters-15
|
[34]: #parameters-15
|
||||||
|
|
||||||
[35]: #makeed25519condition
|
[35]: #makeoutput
|
||||||
|
|
||||||
[36]: #parameters-16
|
[36]: #parameters-16
|
||||||
|
|
||||||
[37]: #makeoutput
|
[37]: #makesha256condition
|
||||||
|
|
||||||
[38]: #parameters-17
|
[38]: #parameters-17
|
||||||
|
|
||||||
[39]: #makesha256condition
|
[39]: #makethresholdcondition
|
||||||
|
|
||||||
[40]: #parameters-18
|
[40]: #parameters-18
|
||||||
|
|
||||||
[41]: #makethresholdcondition
|
[41]: #maketransfertransaction
|
||||||
|
|
||||||
[42]: #parameters-19
|
[42]: #parameters-19
|
||||||
|
|
||||||
[43]: #maketransfertransaction
|
[43]: #signtransaction
|
||||||
|
|
||||||
[44]: #parameters-20
|
[44]: #parameters-20
|
||||||
|
|
||||||
[45]: #signtransaction
|
[45]: #delegatesigntransaction
|
||||||
|
|
||||||
[46]: #parameters-21
|
[46]: #parameters-21
|
||||||
|
|
||||||
[47]: #ccjsonload
|
[47]: #delegatesigntransactionasync
|
||||||
|
|
||||||
[48]: #parameters-22
|
[48]: #parameters-22
|
||||||
|
|
||||||
[49]: #ccjsonify
|
[49]: #ccjsonload
|
||||||
|
|
||||||
[50]: #parameters-23
|
[50]: #parameters-23
|
||||||
|
|
||||||
[51]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/Ed25519Keypair.js#L12-L17 "Source code on GitHub"
|
[51]: #ccjsonify
|
||||||
|
|
||||||
[52]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[52]: #parameters-24
|
||||||
|
|
||||||
[53]: https://nodejs.org/api/buffer.html
|
[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/String
|
[54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[55]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L8-L178 "Source code on GitHub"
|
[55]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[56]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L45-L51 "Source code on GitHub"
|
[56]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[57]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L56-L62 "Source code on GitHub"
|
[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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L68-L74 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L80-L92 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L98-L105 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L110-L116 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L121-L123 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L128-L133 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L139-L144 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L150-L155 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L160-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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L171-L177 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L12-L254 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L18-L25 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L76-L83 "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://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
[71]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L80-L87 "Source code on GitHub"
|
||||||
|
|
||||||
[72]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L92-L103 "Source code on GitHub"
|
[72]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
[73]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[73]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L96-L101 "Source code on GitHub"
|
||||||
|
|
||||||
[74]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L113-L133 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L141-L149 "Source code on GitHub"
|
[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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L158-L172 "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://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[77]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L152-L162 "Source code on GitHub"
|
||||||
|
|
||||||
[78]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L195-L216 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L229-L253 "Source code on GitHub"
|
[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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/utils/ccJsonLoad.js#L10-L40 "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/6a637f33e21a9f43503ec51f923bfdad60c57458/src/utils/ccJsonify.js#L8-L61 "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"
|
||||||
|
|
23
README.md
23
README.md
|
@ -62,6 +62,9 @@ import driver from 'bigchaindb-driver'
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const driver = require('bigchaindb-driver')
|
const driver = require('bigchaindb-driver')
|
||||||
|
const base58 = require('bs58');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const { Ed25519Sha256 } = require('crypto-conditions');
|
||||||
|
|
||||||
// BigchainDB server instance (e.g. https://example.com/api/v1/)
|
// BigchainDB server instance (e.g. https://example.com/api/v1/)
|
||||||
const API_PATH = 'http://localhost:9984/api/v1/'
|
const API_PATH = 'http://localhost:9984/api/v1/'
|
||||||
|
@ -89,6 +92,22 @@ const tx = driver.Transaction.makeCreateTransaction(
|
||||||
// Sign the transaction with private keys
|
// Sign the transaction with private keys
|
||||||
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
|
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
|
||||||
|
|
||||||
|
// 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())
|
||||||
|
|
||||||
// Send the transaction off to BigchainDB
|
// Send the transaction off to BigchainDB
|
||||||
const conn = new driver.Connection(API_PATH)
|
const conn = new driver.Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -105,7 +124,7 @@ conn.postTransactionCommit(txSigned)
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>BigchainDB boilerplate</title>
|
<title>BigchainDB boilerplate</title>
|
||||||
<!-- Adjust version to your needs -->
|
<!-- Adjust version to your needs -->
|
||||||
<script src="https://unpkg.com/bigchaindb-driver@4.0.0/dist/browser/bigchaindb-driver.window.min.js"></script>
|
<script src="https://unpkg.com/bigchaindb-driver@4.2.0/dist/browser/bigchaindb-driver.window.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// BigchainDB server instance (e.g. https://example.com/api/v1/)
|
// BigchainDB server instance (e.g. https://example.com/api/v1/)
|
||||||
|
@ -193,7 +212,7 @@ See the file named [RELEASE_PROCESS.md](RELEASE_PROCESS.md).
|
||||||
## Authors
|
## Authors
|
||||||
|
|
||||||
* inspired by [`js-bigchaindb-quickstart`](https://github.com/sohkai/js-bigchaindb-quickstart) of @sohkhai [thanks]
|
* inspired by [`js-bigchaindb-quickstart`](https://github.com/sohkai/js-bigchaindb-quickstart) of @sohkhai [thanks]
|
||||||
* BigchainDB <devs@bigchaindb.com>
|
* BigchainDB <contact@ipdb.global>
|
||||||
* BigchainDB contributors
|
* BigchainDB contributors
|
||||||
|
|
||||||
## Licenses
|
## Licenses
|
||||||
|
|
|
@ -34,7 +34,7 @@ We follow [BEP-1](https://github.com/bigchaindb/BEPs/tree/master/1), which is ou
|
||||||
|
|
||||||
If that fails, then get it working.
|
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. 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 haver permission to do so).
|
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`
|
`npm login`
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ services:
|
||||||
retries: 3
|
retries: 3
|
||||||
command: -l DEBUG start
|
command: -l DEBUG start
|
||||||
tendermint:
|
tendermint:
|
||||||
image: tendermint/tendermint:0.22.8
|
image: tendermint/tendermint:v0.31.5
|
||||||
# volumes:
|
# volumes:
|
||||||
# - ./tmdata:/tendermint
|
# - ./tmdata:/tendermint
|
||||||
entrypoint: ''
|
entrypoint: ''
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
{
|
{
|
||||||
"presets": ["es2015", "stage-3"],
|
"presets": [["@babel/preset-env"]],
|
||||||
"plugins": ["syntax-async-functions", "transform-runtime", "transform-regenerator", "transform-async-to-generator"]
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -14,23 +14,25 @@
|
||||||
"author": "BigchainDB",
|
"author": "BigchainDB",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.26.0",
|
"@babel/cli": "^7.13.0",
|
||||||
"babel-core": "^6.13.2",
|
"@babel/core": "^7.13.8",
|
||||||
"babel-loader": "^6.2.4",
|
"@babel/eslint-parser": "^7.13.8",
|
||||||
"babel-plugin-syntax-async-functions": "^6.13.0",
|
"@babel/node": "7.13.0",
|
||||||
"babel-plugin-transform-async-to-generator": "^6.8.0",
|
"@babel/plugin-syntax-async-generators": "^7.8.4",
|
||||||
"babel-plugin-transform-regenerator": "^6.11.4",
|
"@babel/plugin-transform-async-to-generator": "^7.13.0",
|
||||||
"babel-plugin-transform-runtime": "^6.12.0",
|
"@babel/plugin-transform-regenerator": "^7.12.13",
|
||||||
"babel-preset-es2015": "^6.13.2",
|
"@babel/plugin-transform-runtime": "^7.13.9",
|
||||||
"babel-preset-stage-3": "^6.11.0",
|
"@babel/preset-env": "^7.13.9",
|
||||||
"nodemon": "^1.14.8",
|
"@babel/register": "^7.13.8",
|
||||||
"rimraf": "^2.6.2"
|
"babel-loader": "^8.2.2",
|
||||||
|
"nodemon": "^2.0.7",
|
||||||
|
"rimraf": "^3.0.2"
|
||||||
},
|
},
|
||||||
"repository": "/",
|
"repository": "/",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bigchaindb-driver": "^4.1.0",
|
"bigchaindb-driver": "^4.1.2",
|
||||||
"bip39": "^2.5.0",
|
"bip39": "^3.0.3",
|
||||||
"dotenv": "^4.0.0"
|
"dotenv": "^8.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,8 @@
|
||||||
const driver = require('bigchaindb-driver')
|
const driver = require('bigchaindb-driver')
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
|
|
||||||
// ======== Preparation ======== //
|
// ======== Preparation ======== //
|
||||||
const conn = new driver.Connection('https://example.com/api/v1/', {
|
const conn = new driver.Connection('https://test.ipdb.io/api/v1/', {
|
||||||
header1: 'header1_value',
|
header1: 'header1_value',
|
||||||
header2: 'header2_value'
|
header2: 'header2_value'
|
||||||
})
|
})
|
||||||
|
@ -26,11 +25,9 @@ const assetdata = {
|
||||||
|
|
||||||
const metadata = { 'planet': 'earth' }
|
const metadata = { 'planet': 'earth' }
|
||||||
|
|
||||||
|
|
||||||
// Call async basic usage function
|
// Call async basic usage function
|
||||||
basicUsage()
|
basicUsage()
|
||||||
|
|
||||||
|
|
||||||
async function basicUsage() {
|
async function basicUsage() {
|
||||||
// ======== Create Transaction Bicycle ======== //
|
// ======== Create Transaction Bicycle ======== //
|
||||||
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
|
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
|
||||||
|
@ -45,7 +42,6 @@ async function basicUsage() {
|
||||||
const txCreateAliceSimpleSigned =
|
const txCreateAliceSimpleSigned =
|
||||||
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
|
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
|
||||||
|
|
||||||
|
|
||||||
// ======== POST CREATE Transaction ======== //
|
// ======== POST CREATE Transaction ======== //
|
||||||
const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned)
|
const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned)
|
||||||
|
|
||||||
|
@ -60,7 +56,6 @@ async function basicUsage() {
|
||||||
|
|
||||||
await conn.postTransactionCommit(txTransferBobSigned)
|
await conn.postTransactionCommit(txTransferBobSigned)
|
||||||
|
|
||||||
|
|
||||||
// ======== Querying Assets ======== //
|
// ======== Querying Assets ======== //
|
||||||
const assets = await conn.searchAssets('Bicycle Inc.')
|
const assets = await conn.searchAssets('Bicycle Inc.')
|
||||||
console.log(assets) // eslint-disable-line no-console
|
console.log(assets) // eslint-disable-line no-console
|
||||||
|
|
|
@ -7,9 +7,8 @@
|
||||||
const driver = require('bigchaindb-driver')
|
const driver = require('bigchaindb-driver')
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
|
|
||||||
// ======== Preparation ======== //
|
// ======== Preparation ======== //
|
||||||
const conn = new driver.Connection('https://example.com/api/v1/', {
|
const conn = new driver.Connection('https://test.ipdb.io/api/v1/', {
|
||||||
header1: 'header1_value',
|
header1: 'header1_value',
|
||||||
header2: 'header2_value'
|
header2: 'header2_value'
|
||||||
})
|
})
|
||||||
|
@ -26,7 +25,6 @@ const assetdata = {
|
||||||
|
|
||||||
const metadata = { 'planet': 'earth' }
|
const metadata = { 'planet': 'earth' }
|
||||||
|
|
||||||
|
|
||||||
// ======== Create Transaction Bicycle ======== //
|
// ======== Create Transaction Bicycle ======== //
|
||||||
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
|
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
|
||||||
assetdata,
|
assetdata,
|
||||||
|
@ -60,7 +58,6 @@ conn.postTransactionCommit(txCreateAliceSimpleSigned)
|
||||||
console.log('Was Alice the previous owner?', tx.inputs[0].owners_before[0] === alice.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 ======== //
|
// ======== Search Asset by Serial Number ======== //
|
||||||
.then(() => conn.searchAssets('Bicycle Inc.'))
|
.then(() => conn.searchAssets('Bicycle Inc.'))
|
||||||
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets)) // eslint-disable-line no-console
|
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets)) // eslint-disable-line no-console
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
const driver = require('bigchaindb-driver')
|
const driver = require('bigchaindb-driver')
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
|
|
||||||
// ======== Preparation ======== //
|
// ======== Preparation ======== //
|
||||||
const conn = new driver.Connection('https://example.com/api/v1/', {
|
const conn = new driver.Connection('https://example.com/api/v1/', {
|
||||||
header1: 'header1_value',
|
header1: 'header1_value',
|
||||||
|
@ -16,7 +15,6 @@ const conn = new driver.Connection('https://example.com/api/v1/', {
|
||||||
|
|
||||||
const alice = new driver.Ed25519Keypair()
|
const alice = new driver.Ed25519Keypair()
|
||||||
|
|
||||||
|
|
||||||
// ======== Asset Array ======== //
|
// ======== Asset Array ======== //
|
||||||
const assetArray = []
|
const assetArray = []
|
||||||
assetArray.push({ 'bicycle': { 'serial_number': 'abc', 'manufacturer': 'BicyclesInc' } })
|
assetArray.push({ 'bicycle': { 'serial_number': 'abc', 'manufacturer': 'BicyclesInc' } })
|
||||||
|
@ -25,7 +23,6 @@ assetArray.push({ 'bicycle': { 'serial_number': 'fgh', 'manufacturer': 'Bicycles
|
||||||
|
|
||||||
const metadata = { 'planet': 'Pluto' }
|
const metadata = { 'planet': 'Pluto' }
|
||||||
|
|
||||||
|
|
||||||
// ======== Create Transactions for bicycles ======== //
|
// ======== Create Transactions for bicycles ======== //
|
||||||
function createTx(assetdata) {
|
function createTx(assetdata) {
|
||||||
const txCreate = driver.Transaction.makeCreateTransaction(
|
const txCreate = driver.Transaction.makeCreateTransaction(
|
||||||
|
@ -41,16 +38,13 @@ function createTx(assetdata) {
|
||||||
return conn.postTransactionCommit(txCreateSigned)
|
return conn.postTransactionCommit(txCreateSigned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======== Execute all promises in order to post transactions and fetch them ======== //
|
// ======== Execute all promises in order to post transactions and fetch them ======== //
|
||||||
Promise.all(assetArray.map(createTx))
|
Promise.all(assetArray.map(createTx))
|
||||||
|
|
||||||
|
|
||||||
// ======== Querying Assets for Assetdata ======== //
|
// ======== Querying Assets for Assetdata ======== //
|
||||||
.then(() => conn.searchAssets('BicyclesInc'))
|
.then(() => conn.searchAssets('BicyclesInc'))
|
||||||
.then(assets => console.log('Found assets with serial number "BicyclesInc":', assets)) // eslint-disable-line no-console
|
.then(assets => console.log('Found assets with serial number "BicyclesInc":', assets)) // eslint-disable-line no-console
|
||||||
|
|
||||||
|
|
||||||
// ======== Querying Assets for Metadata ======== //
|
// ======== Querying Assets for Metadata ======== //
|
||||||
.then(() => conn.searchMetadata('Pluto'))
|
.then(() => conn.searchMetadata('Pluto'))
|
||||||
.then(assets => console.log('Found assets with metadata "Pluto":', assets)) // eslint-disable-line no-console
|
.then(assets => console.log('Found assets with metadata "Pluto":', assets)) // eslint-disable-line no-console
|
||||||
|
|
145
package.json
145
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bigchaindb-driver",
|
"name": "bigchaindb-driver",
|
||||||
"version": "4.1.2",
|
"version": "4.3.0",
|
||||||
"description": "Node.js driver for BigchainDB",
|
"description": "Node.js driver for BigchainDB",
|
||||||
"homepage": "https://www.bigchaindb.com/",
|
"homepage": "https://www.bigchaindb.com/",
|
||||||
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",
|
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",
|
||||||
|
@ -10,82 +10,83 @@
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"author": "BigchainDB",
|
"author": "BigchainDB",
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"types"
|
||||||
|
],
|
||||||
"main": "./dist/node/index.js",
|
"main": "./dist/node/index.js",
|
||||||
"browser": "./dist/browser/bigchaindb-driver.cjs2.min.js",
|
"browser": "./dist/browser/bigchaindb-driver.cjs2.min.js",
|
||||||
|
"types": "./types/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint ./{src,test,examples}/**/*.js",
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix",
|
||||||
"build": "npm run clean && npm run build:cjs && npm run build:dist",
|
"build": "npm run clean && npm run build:cjs && npm run build:dist",
|
||||||
"build:bundle": "webpack",
|
"build:bundle": "webpack",
|
||||||
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
|
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
|
||||||
"build:dist": "cross-env NODE_ENV=production webpack",
|
"build:dist": "cross-env NODE_ENV=production webpack",
|
||||||
"dev": "webpack -w",
|
"dev": "webpack -w",
|
||||||
"clean": "rimraf dist/bundle dist/node",
|
"clean": "rimraf dist/bundle dist/browser dist/node",
|
||||||
"test": "npm run lint && nyc ava test/ && npm run thanks && npm run report-coverage",
|
"test": "npm run lint && nyc ava && npm run report-coverage",
|
||||||
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",
|
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",
|
||||||
"release": "./node_modules/release-it/bin/release-it.js --git.tagName='v${version}' --github.release --npm.publish --non-interactive",
|
"release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it --src.tagName='v%s'",
|
||||||
"release-minor": "./node_modules/release-it/bin/release-it.js minor --git.tagName='v${version}' --github.release --npm.publish --non-interactive",
|
"release-minor": "release-it minor --non-interactive",
|
||||||
"release-major": "./node_modules/release-it/bin/release-it.js major --git.tagName='v${version}' --github.release --npm.publish --non-interactive",
|
"release-major": "release-it major --non-interactive",
|
||||||
"prepublishOnly": "npm run build",
|
"prepublishOnly": "npm run build",
|
||||||
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
|
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
|
||||||
"doc": "node ./node_modules/documentation/bin/documentation.js build src/index.js -f md -o API.md -g --markdown-toc"
|
"doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc"
|
||||||
},
|
|
||||||
"lint-staged": {
|
|
||||||
"*.js": [
|
|
||||||
"eslint"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^0.25.0",
|
"@ava/babel": "^2.0.0",
|
||||||
"babel-cli": "^6.26.0",
|
"@babel/cli": "^7.17.0",
|
||||||
"babel-core": "^6.26.3",
|
"@babel/core": "^7.17.2",
|
||||||
"babel-eslint": "^9.0.0",
|
"@babel/eslint-parser": "^7.17.0",
|
||||||
"babel-loader": "^7.1.5",
|
"@babel/plugin-proposal-export-default-from": "^7.16.7",
|
||||||
"babel-plugin-add-module-exports": "^0.3.1",
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
|
||||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
|
"@babel/plugin-syntax-async-generators": "^7.8.4",
|
||||||
"babel-plugin-transform-export-extensions": "^6.22.0",
|
"@babel/plugin-transform-async-to-generator": "^7.16.8",
|
||||||
"babel-plugin-transform-object-assign": "^6.22.0",
|
"@babel/plugin-transform-object-assign": "^7.16.7",
|
||||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
"@babel/plugin-transform-regenerator": "^7.16.7",
|
||||||
"babel-plugin-transform-runtime": "^6.23.0",
|
"@babel/plugin-transform-runtime": "^7.17.0",
|
||||||
"babel-preset-env": "^1.7.0",
|
"@babel/preset-env": "^7.16.11",
|
||||||
"babel-preset-es2015-no-commonjs": "0.0.2",
|
"@babel/register": "^7.17.0",
|
||||||
"babel-runtime": "^6.26.0",
|
"ava": "^3.15.0",
|
||||||
"cross-env": "^5.2.0",
|
"babel-loader": "^8.2.2",
|
||||||
"documentation": "^10.1.0",
|
"buffer": "^6.0.3",
|
||||||
"eslint": "^5.16.0",
|
"codecov": "^3.8.1",
|
||||||
"eslint-config-ascribe": "^3.0.5",
|
"cross-env": "^7.0.3",
|
||||||
"eslint-plugin-import": "^2.13.0",
|
"documentation": "^13.2.5",
|
||||||
"husky": "^2.1.0",
|
"eslint": "^8.9.0",
|
||||||
"lint-staged": "^8.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"nyc": "^14.0.0",
|
"eslint-plugin-import": "^2.25.4",
|
||||||
"release-it": "^12.6.3",
|
"husky": "^7.0.4",
|
||||||
"rimraf": "^2.6.2",
|
"lint-staged": "^12.3.4",
|
||||||
"sinon": "^7.3.2",
|
"nyc": "^15.1.0",
|
||||||
"webpack": "^4.28.4",
|
"release-it": "^14.12.4",
|
||||||
"webpack-cli": "^3.0.8",
|
"rewire": "^6.0.0",
|
||||||
"webpack-concat-plugin": "^3.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": {
|
"dependencies": {
|
||||||
"browser-resolve": "^1.11.3",
|
"@babel/runtime-corejs3": "^7.17.2",
|
||||||
|
"abort-controller": "^3.0.0",
|
||||||
"bs58": "^4.0.1",
|
"bs58": "^4.0.1",
|
||||||
"buffer": "^5.1.0",
|
"clone": "^2.1.2",
|
||||||
"clone": "^2.1.1",
|
"core-js": "^3.21.0",
|
||||||
"core-js": "^2.6.5",
|
"crypto-conditions": "2.2.1",
|
||||||
"crypto-conditions": "^2.0.1",
|
"decamelize": "^5.0.0",
|
||||||
"decamelize": "^3.2.0",
|
"es6-promise": "^4.2.8",
|
||||||
"es6-promise": "^4.2.4",
|
"fetch-ponyfill": "^7.1.0",
|
||||||
"fetch-ponyfill": "^6.0.1",
|
|
||||||
"isomorphic-fetch": "^2.2.1",
|
|
||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
"js-utility-belt": "^1.5.0",
|
|
||||||
"json-stable-stringify": "^1.0.1",
|
"json-stable-stringify": "^1.0.1",
|
||||||
"query-string": "^6.0.0",
|
"query-string": "^7.1.1",
|
||||||
"rewire": "^4.0.1",
|
"sprintf-js": "^1.1.2",
|
||||||
"sprintf-js": "^1.1.1",
|
"tweetnacl": "^1.0.3"
|
||||||
"tweetnacl": "^1.0.0",
|
|
||||||
"uglifyjs-webpack-plugin": "^2.1.2",
|
|
||||||
"webpack-merge": "^4.1.3",
|
|
||||||
"webpack-sources": "^1.1.0"
|
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bigchaindb",
|
"bigchaindb",
|
||||||
|
@ -94,9 +95,15 @@
|
||||||
"decentralized",
|
"decentralized",
|
||||||
"dapp"
|
"dapp"
|
||||||
],
|
],
|
||||||
|
"lint-staged": {
|
||||||
|
"*.js": [
|
||||||
|
"eslint"
|
||||||
|
]
|
||||||
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"files": [
|
"files": [
|
||||||
"test/*.js"
|
"test/**/*.js",
|
||||||
|
"!test/constants.js"
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"**/*.{js,jsx}",
|
"**/*.{js,jsx}",
|
||||||
|
@ -108,13 +115,29 @@
|
||||||
"tap": true,
|
"tap": true,
|
||||||
"powerAssert": false,
|
"powerAssert": false,
|
||||||
"require": [
|
"require": [
|
||||||
"babel-register"
|
"@babel/register"
|
||||||
],
|
],
|
||||||
"babel": "inherit"
|
"babel": true
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "lint-staged"
|
"pre-commit": "lint-staged"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"release-it": {
|
||||||
|
"github": {
|
||||||
|
"release": true
|
||||||
|
},
|
||||||
|
"git": {
|
||||||
|
"tagName": "v${version}"
|
||||||
|
},
|
||||||
|
"hooks": {
|
||||||
|
"before:init": [
|
||||||
|
"npm run test"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"npm": {
|
||||||
|
"publish": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are 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')
|
const { ConcatSource } = require('webpack-sources')
|
||||||
|
|
||||||
module.exports = class AddVendorsPlugin {
|
module.exports = class AddVendorsPlugin {
|
||||||
|
@ -18,9 +20,9 @@ module.exports = class AddVendorsPlugin {
|
||||||
const vendor = compilation.assets[`vendors.${this.base}`]
|
const vendor = compilation.assets[`vendors.${this.base}`]
|
||||||
|
|
||||||
if (main && vendor) {
|
if (main && vendor) {
|
||||||
const compiledAsset = new ConcatSource(main.children[0])
|
const compiledAsset = new ConcatSource(main._value[0])
|
||||||
compiledAsset.add(vendor)
|
compiledAsset.add(vendor)
|
||||||
compiledAsset.add(main.children[1])
|
compiledAsset.add(main._value[1])
|
||||||
compilation.assets = {}
|
compilation.assets = {}
|
||||||
compilation.assets[this.base] = compiledAsset
|
compilation.assets[this.base] = compiledAsset
|
||||||
} else if (main && mainMap) {
|
} else if (main && mainMap) {
|
||||||
|
@ -28,6 +30,7 @@ module.exports = class AddVendorsPlugin {
|
||||||
compilation.assets[this.base] = main
|
compilation.assets[this.base] = main
|
||||||
compilation.assets[`${this.base}.map`] = mainMap
|
compilation.assets[`${this.base}.map`] = mainMap
|
||||||
}
|
}
|
||||||
|
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import base58 from 'bs58'
|
import base58 from 'bs58'
|
||||||
import nacl from 'tweetnacl'
|
import { sign } from 'tweetnacl'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
|
@ -14,7 +14,7 @@ import nacl from 'tweetnacl'
|
||||||
* @property {string} privateKey
|
* @property {string} privateKey
|
||||||
*/
|
*/
|
||||||
export default function Ed25519Keypair(seed) {
|
export default function Ed25519Keypair(seed) {
|
||||||
const keyPair = seed ? nacl.sign.keyPair.fromSeed(seed) : nacl.sign.keyPair()
|
const keyPair = seed ? sign.keyPair.fromSeed(seed) : sign.keyPair()
|
||||||
this.publicKey = base58.encode(Buffer.from(keyPair.publicKey))
|
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)
|
// tweetnacl's generated secret key is the secret key + public key (resulting in a 64-byte buffer)
|
||||||
this.privateKey = base58.encode(Buffer.from(keyPair.secretKey.slice(0, 32)))
|
this.privateKey = base58.encode(Buffer.from(keyPair.secretKey.slice(0, 32)))
|
||||||
|
|
|
@ -2,36 +2,53 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import {
|
// TODO: remove abort-controller when using Node >=15
|
||||||
Promise
|
import AbortController from 'abort-controller'
|
||||||
} from 'es6-promise'
|
import { Promise } from 'es6-promise'
|
||||||
import fetchPonyfill from 'fetch-ponyfill'
|
import fetchPonyfill from 'fetch-ponyfill'
|
||||||
import {
|
import { vsprintf } from 'sprintf-js'
|
||||||
vsprintf
|
|
||||||
} from 'sprintf-js'
|
|
||||||
|
|
||||||
import formatText from './format_text'
|
import formatText from './format_text'
|
||||||
import stringifyAsQueryParam from './stringify_as_query_param'
|
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
|
* @private
|
||||||
* Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564
|
* Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564
|
||||||
* @param {integer} obj Source object
|
* @param {integer} obj Source object
|
||||||
* @param {Promise} filter Array of key names to select or function to invoke per iteration
|
* @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
|
* @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved
|
||||||
*/
|
*/
|
||||||
function timeout(ms, promise) {
|
function timeout(ms, promise, controller) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
const nodeTimeout = setTimeout(() => {
|
||||||
|
controller.abort()
|
||||||
const errorObject = {
|
const errorObject = {
|
||||||
message: 'TimeoutError'
|
message: 'TimeoutError',
|
||||||
}
|
}
|
||||||
reject(new Error(errorObject))
|
reject(new Error(errorObject))
|
||||||
}, ms)
|
}, ms)
|
||||||
promise.then(resolve, reject)
|
promise
|
||||||
|
.then((res) => {
|
||||||
|
clearTimeout(nodeTimeout)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
clearTimeout(nodeTimeout)
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,17 +62,15 @@ function handleResponse(res) {
|
||||||
// If status is not a 2xx (based on Response.ok), assume it's an error
|
// 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
|
// See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch
|
||||||
if (!(res && res.ok)) {
|
if (!(res && res.ok)) {
|
||||||
const errorObject = {
|
throw new ResponseError(
|
||||||
message: 'HTTP Error: Requested page not reachable',
|
'HTTP Error: Requested page not reachable',
|
||||||
status: `${res.status} ${res.statusText}`,
|
`${res.status} ${res.statusText}`,
|
||||||
requestURI: res.url
|
res.url
|
||||||
}
|
)
|
||||||
throw errorObject
|
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* imported from https://github.com/bigchaindb/js-utility-belt/
|
* imported from https://github.com/bigchaindb/js-utility-belt/
|
||||||
|
@ -85,25 +100,30 @@ function handleResponse(res) {
|
||||||
* @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the
|
* @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the
|
||||||
* Promise with the handleResponse function
|
* Promise with the handleResponse function
|
||||||
*/
|
*/
|
||||||
export default function baseRequest(url, {
|
export default function baseRequest(
|
||||||
jsonBody,
|
url,
|
||||||
query,
|
{
|
||||||
urlTemplateSpec,
|
jsonBody, query, urlTemplateSpec, ...fetchConfig
|
||||||
...fetchConfig
|
} = {},
|
||||||
} = {}, requestTimeout) {
|
requestTimeout = 0
|
||||||
|
) {
|
||||||
let expandedUrl = url
|
let expandedUrl = url
|
||||||
|
|
||||||
if (urlTemplateSpec != null) {
|
if (urlTemplateSpec != null) {
|
||||||
if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) {
|
if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) {
|
||||||
// Use vsprintf for the array call signature
|
// Use vsprintf for the array call signature
|
||||||
expandedUrl = vsprintf(url, urlTemplateSpec)
|
expandedUrl = vsprintf(url, urlTemplateSpec)
|
||||||
} else if (urlTemplateSpec &&
|
} else if (
|
||||||
|
urlTemplateSpec &&
|
||||||
typeof urlTemplateSpec === 'object' &&
|
typeof urlTemplateSpec === 'object' &&
|
||||||
Object.keys(urlTemplateSpec).length) {
|
Object.keys(urlTemplateSpec).length
|
||||||
|
) {
|
||||||
expandedUrl = formatText(url, urlTemplateSpec)
|
expandedUrl = formatText(url, urlTemplateSpec)
|
||||||
} else if (process.env.NODE_ENV !== 'production') {
|
} else if (process.env.NODE_ENV !== 'production') {
|
||||||
// eslint-disable-next-line no-console
|
// 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...'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,11 +141,17 @@ export default function baseRequest(url, {
|
||||||
if (jsonBody != null) {
|
if (jsonBody != null) {
|
||||||
fetchConfig.body = JSON.stringify(jsonBody)
|
fetchConfig.body = JSON.stringify(jsonBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestTimeout) {
|
if (requestTimeout) {
|
||||||
return timeout(requestTimeout, fetch.fetch(expandedUrl, fetchConfig))
|
const controller = new AbortController()
|
||||||
|
const { signal } = controller
|
||||||
|
return timeout(
|
||||||
|
requestTimeout,
|
||||||
|
fetch.fetch(expandedUrl, { ...fetchConfig, signal }),
|
||||||
|
controller
|
||||||
|
)
|
||||||
.then(handleResponse)
|
.then(handleResponse)
|
||||||
} else {
|
} else {
|
||||||
return fetch.fetch(expandedUrl, fetchConfig)
|
return fetch.fetch(expandedUrl, fetchConfig).then(handleResponse)
|
||||||
.then(handleResponse)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default class Connection {
|
||||||
// This driver implements the BEP-14 https://github.com/bigchaindb/BEPs/tree/master/14
|
// This driver implements the BEP-14 https://github.com/bigchaindb/BEPs/tree/master/14
|
||||||
constructor(nodes, headers = {}, timeout = DEFAULT_TIMEOUT) {
|
constructor(nodes, headers = {}, timeout = DEFAULT_TIMEOUT) {
|
||||||
// Copy object
|
// Copy object
|
||||||
this.headers = Object.assign({}, headers)
|
this.headers = { ...headers }
|
||||||
|
|
||||||
// Validate headers
|
// Validate headers
|
||||||
Object.keys(headers).forEach(header => {
|
Object.keys(headers).forEach(header => {
|
||||||
|
@ -49,7 +49,7 @@ export default class Connection {
|
||||||
if (typeof node === 'string') {
|
if (typeof node === 'string') {
|
||||||
return { 'endpoint': node, 'headers': headers }
|
return { 'endpoint': node, 'headers': headers }
|
||||||
} else {
|
} else {
|
||||||
const allHeaders = Object.assign({}, headers, node.headers)
|
const allHeaders = { ...headers, ...node.headers }
|
||||||
return { 'endpoint': node.endpoint, 'headers': allHeaders }
|
return { 'endpoint': node.endpoint, 'headers': allHeaders }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,6 @@ export default class Connection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param transaction
|
* @param transaction
|
||||||
*/
|
*/
|
||||||
|
@ -166,7 +165,6 @@ export default class Connection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param transaction
|
* @param transaction
|
||||||
*/
|
*/
|
||||||
|
@ -180,10 +178,11 @@ export default class Connection {
|
||||||
/**
|
/**
|
||||||
* @param search
|
* @param search
|
||||||
*/
|
*/
|
||||||
searchAssets(search) {
|
searchAssets(search, limit = 10) {
|
||||||
return this._req(Connection.getApiUrls('assets'), {
|
return this._req(Connection.getApiUrls('assets'), {
|
||||||
query: {
|
query: {
|
||||||
search
|
search,
|
||||||
|
limit
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -191,10 +190,11 @@ export default class Connection {
|
||||||
/**
|
/**
|
||||||
* @param search
|
* @param search
|
||||||
*/
|
*/
|
||||||
searchMetadata(search) {
|
searchMetadata(search, limit = 10) {
|
||||||
return this._req(Connection.getApiUrls('metadata'), {
|
return this._req(Connection.getApiUrls('metadata'), {
|
||||||
query: {
|
query: {
|
||||||
search
|
search,
|
||||||
|
limit
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
import { sprintf } from 'sprintf-js'
|
import { sprintf } from 'sprintf-js'
|
||||||
|
|
||||||
|
|
||||||
// Regexes taken from or inspired by sprintf-js
|
// Regexes taken from or inspired by sprintf-js
|
||||||
const Regex = {
|
const Regex = {
|
||||||
TEMPLATE_LITERAL: /\${([^)]+?)}/g,
|
TEMPLATE_LITERAL: /\${([^)]+?)}/g,
|
||||||
|
|
13
src/index.js
13
src/index.js
|
@ -2,9 +2,12 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are 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 Connection from './connection'
|
export {
|
||||||
export Transaction from './transaction'
|
ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction
|
||||||
export ccJsonLoad from './utils/ccJsonLoad'
|
}
|
||||||
export ccJsonify from './utils/ccJsonify'
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ const ERROR_FROM_SERVER = 'HTTP Error: Requested page not reachable'
|
||||||
* default settings, and response handling.
|
* default settings, and response handling.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
export default class Request {
|
export default class Request {
|
||||||
constructor(node) {
|
constructor(node) {
|
||||||
this.node = node
|
this.node = node
|
||||||
|
@ -33,14 +32,15 @@ export default class Request {
|
||||||
return Promise.reject(new Error('Request was not given a url.'))
|
return Promise.reject(new Error('Request was not given a url.'))
|
||||||
}
|
}
|
||||||
// Load default fetch configuration and remove any falsy query parameters
|
// Load default fetch configuration and remove any falsy query parameters
|
||||||
const requestConfig = Object.assign({}, this.node.headers, DEFAULT_REQUEST_CONFIG, config, {
|
const requestConfig = {
|
||||||
|
...this.node.headers,
|
||||||
|
...DEFAULT_REQUEST_CONFIG,
|
||||||
|
...config,
|
||||||
query: config.query && sanitize(config.query)
|
query: config.query && sanitize(config.query)
|
||||||
})
|
}
|
||||||
const apiUrl = this.node.endpoint + urlPath
|
const apiUrl = this.node.endpoint + urlPath
|
||||||
if (requestConfig.jsonBody) {
|
if (requestConfig.jsonBody) {
|
||||||
requestConfig.headers = Object.assign({}, requestConfig.headers, {
|
requestConfig.headers = { ...requestConfig.headers, 'Content-Type': 'application/json' }
|
||||||
'Content-Type': 'application/json'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If connectionError occurs, a timestamp equal to now +
|
// If connectionError occurs, a timestamp equal to now +
|
||||||
|
@ -70,7 +70,7 @@ export default class Request {
|
||||||
|
|
||||||
const requestTimeout = timeout ? timeout - backoffTimedelta : timeout
|
const requestTimeout = timeout ? timeout - backoffTimedelta : timeout
|
||||||
return baseRequest(apiUrl, requestConfig, requestTimeout)
|
return baseRequest(apiUrl, requestConfig, requestTimeout)
|
||||||
.then(async (res) => {
|
.then((res) => {
|
||||||
this.connectionError = null
|
this.connectionError = null
|
||||||
return res.json()
|
return res.json()
|
||||||
})
|
})
|
||||||
|
@ -111,6 +111,8 @@ export default class Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
static sleep(ms) {
|
static sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import coreIncludes from 'core-js/library/fn/array/includes'
|
import 'core-js/features/array/includes'
|
||||||
import coreObjectEntries from 'core-js/library/fn/object/entries'
|
import 'core-js/features/object/entries'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -14,8 +13,8 @@ import coreObjectEntries from 'core-js/library/fn/object/entries'
|
||||||
*/
|
*/
|
||||||
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
|
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
|
||||||
if (filter && Array.isArray(filter)) {
|
if (filter && Array.isArray(filter)) {
|
||||||
return applyFilterOnObject(obj, isInclusion ? (val => coreIncludes(filter, val))
|
return applyFilterOnObject(obj, isInclusion ? (val => filter.includes(val))
|
||||||
: (val => !coreIncludes(filter, val)))
|
: (val => !filter.includes(val)))
|
||||||
} else if (filter && typeof filter === 'function') {
|
} else if (filter && typeof filter === 'function') {
|
||||||
// Flip the filter fn's return if it's for inclusion
|
// Flip the filter fn's return if it's for inclusion
|
||||||
return applyFilterOnObject(obj, isInclusion ? filter
|
return applyFilterOnObject(obj, isInclusion ? filter
|
||||||
|
@ -32,11 +31,11 @@ function filterFromObject(obj, filter, { isInclusion = true } = {}) {
|
||||||
*/
|
*/
|
||||||
function applyFilterOnObject(obj, filterFn) {
|
function applyFilterOnObject(obj, filterFn) {
|
||||||
if (filterFn == null) {
|
if (filterFn == null) {
|
||||||
return Object.assign({}, obj)
|
return { ...obj }
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredObj = {}
|
const filteredObj = {}
|
||||||
coreObjectEntries(obj).forEach(([key, val]) => {
|
Object.entries(obj).forEach(([key, val]) => {
|
||||||
if (filterFn(val, key)) {
|
if (filterFn(val, key)) {
|
||||||
filteredObj[key] = val
|
filteredObj[key] = val
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import sha3 from 'js-sha3'
|
/* eslint-disable camelcase */
|
||||||
|
import { sha3_256 } from 'js-sha3'
|
||||||
|
|
||||||
export default function sha256Hash(data) {
|
export default function sha256Hash(data) {
|
||||||
return sha3.sha3_256
|
return sha3_256
|
||||||
.create()
|
.create()
|
||||||
.update(data)
|
.update(data)
|
||||||
.hex()
|
.hex()
|
||||||
}
|
}
|
||||||
|
/* eslint-enable camelcase */
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import coreObjectEntries from 'core-js/library/fn/object/entries'
|
import 'core-js/features/object/entries'
|
||||||
import decamelize from 'decamelize'
|
import decamelize from 'decamelize'
|
||||||
import queryString from 'query-string'
|
import queryString from 'query-string'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* imported from https://github.com/bigchaindb/js-utility-belt/
|
* imported from https://github.com/bigchaindb/js-utility-belt/
|
||||||
|
@ -38,7 +37,7 @@ export default function stringifyAsQueryParam(obj, transform = decamelize) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformedKeysObj = coreObjectEntries(obj).reduce((paramsObj, [key, value]) => {
|
const transformedKeysObj = Object.entries(obj).reduce((paramsObj, [key, value]) => {
|
||||||
paramsObj[transform(key)] = value
|
paramsObj[transform(key)] = value
|
||||||
return paramsObj
|
return paramsObj
|
||||||
}, {})
|
}, {})
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import { Buffer } from 'buffer'
|
|
||||||
import stableStringify from 'json-stable-stringify'
|
import stableStringify from 'json-stable-stringify'
|
||||||
import clone from 'clone'
|
import clone from 'clone'
|
||||||
import base58 from 'bs58'
|
import base58 from 'bs58'
|
||||||
import cc from 'crypto-conditions'
|
import { Ed25519Sha256, PreimageSha256, ThresholdSha256 } from 'crypto-conditions'
|
||||||
import ccJsonify from './utils/ccJsonify'
|
import ccJsonify from './utils/ccJsonify'
|
||||||
import sha256Hash from './sha256Hash'
|
import sha256Hash from './sha256Hash'
|
||||||
|
|
||||||
|
@ -38,13 +37,13 @@ export default class Transaction {
|
||||||
|
|
||||||
static makeTransactionTemplate() {
|
static makeTransactionTemplate() {
|
||||||
const txTemplate = {
|
const txTemplate = {
|
||||||
'id': null,
|
id: null,
|
||||||
'operation': null,
|
operation: null,
|
||||||
'outputs': [],
|
outputs: [],
|
||||||
'inputs': [],
|
inputs: [],
|
||||||
'metadata': null,
|
metadata: null,
|
||||||
'asset': null,
|
asset: null,
|
||||||
'version': '2.0',
|
version: '2.0',
|
||||||
}
|
}
|
||||||
return txTemplate
|
return txTemplate
|
||||||
}
|
}
|
||||||
|
@ -79,7 +78,7 @@ export default class Transaction {
|
||||||
*/
|
*/
|
||||||
static makeCreateTransaction(asset, metadata, outputs, ...issuers) {
|
static makeCreateTransaction(asset, metadata, outputs, ...issuers) {
|
||||||
const assetDefinition = {
|
const assetDefinition = {
|
||||||
'data': asset || null,
|
data: asset || null,
|
||||||
}
|
}
|
||||||
const inputs = issuers.map((issuer) => Transaction.makeInputTemplate([issuer]))
|
const inputs = issuers.map((issuer) => Transaction.makeInputTemplate([issuer]))
|
||||||
|
|
||||||
|
@ -94,16 +93,10 @@ export default class 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)
|
||||||
*/
|
*/
|
||||||
static makeEd25519Condition(publicKey, json = true) {
|
static makeEd25519Condition(publicKey, json = true) {
|
||||||
const publicKeyBuffer = Buffer.from(base58.decode(publicKey))
|
const publicKeyBuffer = base58.decode(publicKey)
|
||||||
|
const ed25519Fulfillment = new Ed25519Sha256()
|
||||||
const ed25519Fulfillment = new cc.Ed25519Sha256()
|
|
||||||
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
|
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
|
||||||
|
return json ? ccJsonify(ed25519Fulfillment) : ed25519Fulfillment
|
||||||
if (json) {
|
|
||||||
return ccJsonify(ed25519Fulfillment)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ed25519Fulfillment
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,8 +124,8 @@ export default class Transaction {
|
||||||
getPublicKeys(condition.details)
|
getPublicKeys(condition.details)
|
||||||
return {
|
return {
|
||||||
condition,
|
condition,
|
||||||
'amount': amount,
|
amount,
|
||||||
'public_keys': publicKeys,
|
public_keys: publicKeys,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,13 +136,9 @@ export default class Transaction {
|
||||||
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
|
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
|
||||||
*/
|
*/
|
||||||
static makeSha256Condition(preimage, json = true) {
|
static makeSha256Condition(preimage, json = true) {
|
||||||
const sha256Fulfillment = new cc.PreimageSha256()
|
const sha256Fulfillment = new PreimageSha256()
|
||||||
sha256Fulfillment.preimage = Buffer.from(preimage)
|
sha256Fulfillment.setPreimage(Buffer.from(preimage))
|
||||||
|
return json ? ccJsonify(sha256Fulfillment) : sha256Fulfillment
|
||||||
if (json) {
|
|
||||||
return ccJsonify(sha256Fulfillment)
|
|
||||||
}
|
|
||||||
return sha256Fulfillment
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,19 +149,15 @@ export default class Transaction {
|
||||||
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
|
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
|
||||||
*/
|
*/
|
||||||
static makeThresholdCondition(threshold, subconditions = [], json = true) {
|
static makeThresholdCondition(threshold, subconditions = [], json = true) {
|
||||||
const thresholdCondition = new cc.ThresholdSha256()
|
const thresholdCondition = new ThresholdSha256()
|
||||||
thresholdCondition.threshold = threshold
|
thresholdCondition.setThreshold(threshold)
|
||||||
|
|
||||||
subconditions.forEach((subcondition) => {
|
subconditions.forEach((subcondition) => {
|
||||||
// TODO: add support for Condition and URIs
|
// TODO: add support for Condition
|
||||||
thresholdCondition.addSubfulfillment(subcondition)
|
thresholdCondition.addSubfulfillment(subcondition)
|
||||||
|
// ? Should be thresholdCondition.addSubcondition(subcondition)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (json) {
|
return json ? ccJsonify(thresholdCondition) : thresholdCondition
|
||||||
return ccJsonify(thresholdCondition)
|
|
||||||
}
|
|
||||||
|
|
||||||
return thresholdCondition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,15 +190,15 @@ export default class Transaction {
|
||||||
const { tx, outputIndex } = { tx: unspentOutput.tx, outputIndex: unspentOutput.output_index }
|
const { tx, outputIndex } = { tx: unspentOutput.tx, outputIndex: unspentOutput.output_index }
|
||||||
const fulfilledOutput = tx.outputs[outputIndex]
|
const fulfilledOutput = tx.outputs[outputIndex]
|
||||||
const transactionLink = {
|
const transactionLink = {
|
||||||
'output_index': outputIndex,
|
output_index: outputIndex,
|
||||||
'transaction_id': tx.id,
|
transaction_id: tx.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
return Transaction.makeInputTemplate(fulfilledOutput.public_keys, transactionLink)
|
return Transaction.makeInputTemplate(fulfilledOutput.public_keys, transactionLink)
|
||||||
})
|
})
|
||||||
|
|
||||||
const assetLink = {
|
const assetLink = {
|
||||||
'id': unspentOutputs[0].tx.operation === 'CREATE' ? unspentOutputs[0].tx.id
|
id: unspentOutputs[0].tx.operation === 'CREATE' ? unspentOutputs[0].tx.id
|
||||||
: unspentOutputs[0].tx.asset.id
|
: unspentOutputs[0].tx.asset.id
|
||||||
}
|
}
|
||||||
return Transaction.makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
|
return Transaction.makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
|
||||||
|
@ -237,13 +222,13 @@ export default class Transaction {
|
||||||
|
|
||||||
signedTx.inputs.forEach((input, index) => {
|
signedTx.inputs.forEach((input, index) => {
|
||||||
const privateKey = privateKeys[index]
|
const privateKey = privateKeys[index]
|
||||||
const privateKeyBuffer = Buffer.from(base58.decode(privateKey))
|
const privateKeyBuffer = base58.decode(privateKey)
|
||||||
|
|
||||||
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
|
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
|
||||||
.concat(input.fulfills.transaction_id)
|
.concat(input.fulfills.transaction_id)
|
||||||
.concat(input.fulfills.output_index) : serializedTransaction
|
.concat(input.fulfills.output_index) : serializedTransaction
|
||||||
const transactionHash = sha256Hash(transactionUniqueFulfillment)
|
const transactionHash = sha256Hash(transactionUniqueFulfillment)
|
||||||
const ed25519Fulfillment = new cc.Ed25519Sha256()
|
const ed25519Fulfillment = new Ed25519Sha256()
|
||||||
ed25519Fulfillment.sign(Buffer.from(transactionHash, 'hex'), privateKeyBuffer)
|
ed25519Fulfillment.sign(Buffer.from(transactionHash, 'hex'), privateKeyBuffer)
|
||||||
const fulfillmentUri = ed25519Fulfillment.serializeUri()
|
const fulfillmentUri = ed25519Fulfillment.serializeUri()
|
||||||
|
|
||||||
|
@ -255,4 +240,48 @@ export default class Transaction {
|
||||||
signedTx.id = sha256Hash(serializedSignedTransaction)
|
signedTx.id = sha256Hash(serializedSignedTransaction)
|
||||||
return signedTx
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
import Request from './request'
|
import Request from './request'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -13,7 +12,6 @@ import Request from './request'
|
||||||
* customizable in the future).
|
* customizable in the future).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
export default class Transport {
|
export default class Transport {
|
||||||
constructor(nodes, timeout) {
|
constructor(nodes, timeout) {
|
||||||
this.connectionPool = []
|
this.connectionPool = []
|
||||||
|
@ -46,28 +44,21 @@ export default class Transport {
|
||||||
connection = this.pickConnection()
|
connection = this.pickConnection()
|
||||||
// Date in milliseconds
|
// Date in milliseconds
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
try {
|
// eslint-disable-next-line no-await-in-loop
|
||||||
// eslint-disable-next-line no-await-in-loop
|
response = await connection.request(
|
||||||
response = await connection.request(
|
path,
|
||||||
path,
|
headers,
|
||||||
headers,
|
this.timeout,
|
||||||
this.timeout,
|
this.maxBackoffTime
|
||||||
this.maxBackoffTime
|
)
|
||||||
)
|
const elapsed = Date.now() - startTime
|
||||||
const elapsed = Date.now() - startTime
|
if (connection.backoffTime > 0 && this.timeout > 0) {
|
||||||
if (connection.backoffTime > 0 && this.timeout > 0) {
|
this.timeout -= elapsed
|
||||||
this.timeout -= elapsed
|
} else {
|
||||||
} else {
|
// No connection error, the response is valid
|
||||||
// No connection error, the response is valid
|
return response
|
||||||
return response
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const errorObject = {
|
throw new Error('TimeoutError')
|
||||||
message: 'TimeoutError',
|
|
||||||
}
|
|
||||||
throw errorObject
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import { Buffer } from 'buffer'
|
|
||||||
import base58 from 'bs58'
|
import base58 from 'bs58'
|
||||||
import cc from 'crypto-conditions'
|
import { Condition, Ed25519Sha256, ThresholdSha256 } from 'crypto-conditions'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
|
* Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
|
||||||
|
@ -13,17 +12,18 @@ import cc from 'crypto-conditions'
|
||||||
*/
|
*/
|
||||||
export default function ccJsonLoad(conditionJson) {
|
export default function ccJsonLoad(conditionJson) {
|
||||||
if ('hash' in conditionJson) {
|
if ('hash' in conditionJson) {
|
||||||
const condition = new cc.Condition()
|
const condition = new Condition()
|
||||||
condition.type = conditionJson.type_id
|
condition.setTypeId(conditionJson.type_id)
|
||||||
condition.bitmask = conditionJson.bitmask
|
condition.setSubtypes(conditionJson.bitmask)
|
||||||
condition.hash = Buffer.from(base58.decode(conditionJson.hash))
|
condition.setHash(base58.decode(conditionJson.hash))
|
||||||
|
// TODO: fix this, maxFulfillmentLength cannot be set in CryptoCondition lib
|
||||||
condition.maxFulfillmentLength = parseInt(conditionJson.max_fulfillment_length, 10)
|
condition.maxFulfillmentLength = parseInt(conditionJson.max_fulfillment_length, 10)
|
||||||
return condition
|
return condition
|
||||||
} else {
|
} else {
|
||||||
let fulfillment
|
let fulfillment
|
||||||
|
|
||||||
if (conditionJson.type === 'threshold-sha-256') {
|
if (conditionJson.type === 'threshold-sha-256') {
|
||||||
fulfillment = new cc.ThresholdSha256()
|
fulfillment = new ThresholdSha256()
|
||||||
fulfillment.threshold = conditionJson.threshold
|
fulfillment.threshold = conditionJson.threshold
|
||||||
conditionJson.subconditions.forEach((subconditionJson) => {
|
conditionJson.subconditions.forEach((subconditionJson) => {
|
||||||
const subcondition = ccJsonLoad(subconditionJson)
|
const subcondition = ccJsonLoad(subconditionJson)
|
||||||
|
@ -36,8 +36,8 @@ export default function ccJsonLoad(conditionJson) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conditionJson.type === 'ed25519-sha-256') {
|
if (conditionJson.type === 'ed25519-sha-256') {
|
||||||
fulfillment = new cc.Ed25519Sha256()
|
fulfillment = new Ed25519Sha256()
|
||||||
fulfillment.publicKey = Buffer.from(base58.decode(conditionJson.public_key))
|
fulfillment.setPublicKey(base58.decode(conditionJson.public_key))
|
||||||
}
|
}
|
||||||
return fulfillment
|
return fulfillment
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ export default function ccJsonify(fulfillment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonBody = {
|
const jsonBody = {
|
||||||
'details': {},
|
details: {},
|
||||||
'uri': conditionUri,
|
uri: conditionUri,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fulfillment.getTypeId() === 0) {
|
if (fulfillment.getTypeId() === 0) {
|
||||||
|
@ -35,15 +35,15 @@ export default function ccJsonify(fulfillment) {
|
||||||
|
|
||||||
if (fulfillment.getTypeId() === 2) {
|
if (fulfillment.getTypeId() === 2) {
|
||||||
return {
|
return {
|
||||||
'details': {
|
details: {
|
||||||
'type': 'threshold-sha-256',
|
type: 'threshold-sha-256',
|
||||||
'threshold': fulfillment.threshold,
|
threshold: fulfillment.threshold,
|
||||||
'subconditions': fulfillment.subconditions.map((subcondition) => {
|
subconditions: fulfillment.subconditions.map((subcondition) => {
|
||||||
const subconditionJson = ccJsonify(subcondition.body)
|
const subconditionJson = ccJsonify(subcondition.body)
|
||||||
return subconditionJson.details
|
return subconditionJson.details
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
'uri': conditionUri,
|
uri: conditionUri,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,11 @@ test('HandleResponse does not throw error for response ok', t => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('baseRequest test query and vsprint', async t => {
|
test('baseRequest test query and vsprint', async t => {
|
||||||
const target = {
|
const error = await t.throwsAsync(baseRequest('https://%s.com/', {
|
||||||
message: 'HTTP Error: Requested page not reachable',
|
|
||||||
requestURI: 'https://www.google.com/teapot',
|
|
||||||
status: '418 I\'m a Teapot',
|
|
||||||
}
|
|
||||||
const error = await t.throws(baseRequest('https://%s.com/', {
|
|
||||||
urlTemplateSpec: ['google'],
|
urlTemplateSpec: ['google'],
|
||||||
query: 'teapot'
|
query: 'teapot'
|
||||||
}))
|
}), { instanceOf: Error, message: 'HTTP Error: Requested page not reachable' })
|
||||||
t.deepEqual(target, error)
|
|
||||||
|
t.is(error.requestURI, 'https://www.google.com/teapot')
|
||||||
|
t.is(error.status, '418 I\'m a Teapot')
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,8 +22,13 @@ test('Payload thrown at incorrect API_PATH', async t => {
|
||||||
status: '404 NOT FOUND',
|
status: '404 NOT FOUND',
|
||||||
requestURI: 'http://localhost:9984/api/wrong/transactions/transactionId'
|
requestURI: 'http://localhost:9984/api/wrong/transactions/transactionId'
|
||||||
}
|
}
|
||||||
const error = await t.throws(connection.getTransaction('transactionId'))
|
const error = await t.throwsAsync(connection.getTransaction('transactionId'), {
|
||||||
t.deepEqual(target, error)
|
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 => {
|
test('Generate API URLS', t => {
|
||||||
|
@ -100,7 +105,6 @@ test('Request with custom headers', t => {
|
||||||
t.truthy(testConn.transport.forwardRequest.calledWith(PATH, expectedOptions))
|
t.truthy(testConn.transport.forwardRequest.calledWith(PATH, expectedOptions))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get block for a block id', t => {
|
test('Get block for a block id', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const blockHeight = 'abc'
|
const blockHeight = 'abc'
|
||||||
|
@ -115,7 +119,6 @@ test('Get block for a block id', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get transaction for a transaction id', t => {
|
test('Get transaction for a transaction id', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const transactionId = 'abc'
|
const transactionId = 'abc'
|
||||||
|
@ -130,7 +133,6 @@ test('Get transaction for a transaction id', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get list of blocks for a transaction id', t => {
|
test('Get list of blocks for a transaction id', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const transactionId = 'abc'
|
const transactionId = 'abc'
|
||||||
|
@ -149,7 +151,6 @@ test('Get list of blocks for a transaction id', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get list of transactions for an asset id', t => {
|
test('Get list of transactions for an asset id', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const assetId = 'abc'
|
const assetId = 'abc'
|
||||||
|
@ -170,7 +171,6 @@ test('Get list of transactions for an asset id', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get outputs for a public key and no spent flag', t => {
|
test('Get outputs for a public key and no spent flag', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const publicKey = 'publicKey'
|
const publicKey = 'publicKey'
|
||||||
|
@ -185,7 +185,6 @@ test('Get outputs for a public key and no spent flag', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get outputs for a public key and spent=false', t => {
|
test('Get outputs for a public key and spent=false', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const publicKey = 'publicKey'
|
const publicKey = 'publicKey'
|
||||||
|
@ -201,7 +200,6 @@ test('Get outputs for a public key and spent=false', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get outputs for a public key and spent=true', t => {
|
test('Get outputs for a public key and spent=true', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const publicKey = 'publicKey'
|
const publicKey = 'publicKey'
|
||||||
|
@ -217,7 +215,6 @@ test('Get outputs for a public key and spent=true', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get asset for text', t => {
|
test('Get asset for text', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const search = 'abc'
|
const search = 'abc'
|
||||||
|
@ -228,11 +225,10 @@ test('Get asset for text', t => {
|
||||||
conn.searchAssets(search)
|
conn.searchAssets(search)
|
||||||
t.truthy(conn._req.calledWith(
|
t.truthy(conn._req.calledWith(
|
||||||
expectedPath,
|
expectedPath,
|
||||||
{ query: { search } }
|
{ query: { search, limit: 10 } }
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Get metadata for text', t => {
|
test('Get metadata for text', t => {
|
||||||
const expectedPath = 'path'
|
const expectedPath = 'path'
|
||||||
const search = 'abc'
|
const search = 'abc'
|
||||||
|
@ -243,6 +239,6 @@ test('Get metadata for text', t => {
|
||||||
conn.searchMetadata(search)
|
conn.searchMetadata(search)
|
||||||
t.truthy(conn._req.calledWith(
|
t.truthy(conn._req.calledWith(
|
||||||
expectedPath,
|
expectedPath,
|
||||||
{ query: { search } }
|
{ query: { search, limit: 10 } }
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import test from 'ava'
|
import { createHash } from 'crypto'
|
||||||
|
import base58 from 'bs58'
|
||||||
|
import { Ed25519Sha256 } from 'crypto-conditions'
|
||||||
import { Transaction, Ed25519Keypair } from '../src'
|
import { Transaction, Ed25519Keypair } from '../src'
|
||||||
// TODO: Find out if ava has something like conftest, if so put this there.
|
// TODO: Find out if ava has something like conftest, if so put this there.
|
||||||
|
|
||||||
|
@ -31,6 +33,21 @@ export const bob = new Ed25519Keypair()
|
||||||
export const bobCondition = Transaction.makeEd25519Condition(bob.publicKey)
|
export const bobCondition = Transaction.makeEd25519Condition(bob.publicKey)
|
||||||
export const bobOutput = Transaction.makeOutput(bobCondition)
|
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)
|
||||||
|
)
|
||||||
|
|
||||||
// TODO: https://github.com/avajs/ava/issues/1190
|
const ed25519Fulfillment = new Ed25519Sha256()
|
||||||
test('', () => 'dirty hack. TODO: Exclude this file from being run by ava')
|
filteredKeyPairs.forEach(keyPair => {
|
||||||
|
const privateKey = Buffer.from(base58.decode(keyPair.privateKey))
|
||||||
|
ed25519Fulfillment.sign(transactionHash, privateKey)
|
||||||
|
})
|
||||||
|
return ed25519Fulfillment.serializeUri()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@ import {
|
||||||
bob,
|
bob,
|
||||||
bobOutput,
|
bobOutput,
|
||||||
asset,
|
asset,
|
||||||
metaData
|
metaData,
|
||||||
|
delegatedSignTransaction
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
|
|
||||||
|
|
||||||
test('Keypair is created', t => {
|
test('Keypair is created', t => {
|
||||||
const keyPair = new Ed25519Keypair()
|
const keyPair = new Ed25519Keypair()
|
||||||
|
|
||||||
|
@ -24,10 +24,6 @@ test('Keypair is created', t => {
|
||||||
t.truthy(keyPair.privateKey)
|
t.truthy(keyPair.privateKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// TODO: The following tests are a bit messy currently, please do:
|
|
||||||
//
|
|
||||||
// - tidy up dependency on `pollStatusAndFetchTransaction`
|
|
||||||
test('Valid CREATE transaction with default node', t => {
|
test('Valid CREATE transaction with default node', t => {
|
||||||
const conn = new Connection()
|
const conn = new Connection()
|
||||||
|
|
||||||
|
@ -45,7 +41,6 @@ test('Valid CREATE transaction with default node', t => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Valid CREATE transaction using async', t => {
|
test('Valid CREATE transaction using async', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -61,7 +56,6 @@ test('Valid CREATE transaction using async', t => {
|
||||||
.then(resTx => t.truthy(resTx))
|
.then(resTx => t.truthy(resTx))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Valid CREATE transaction using sync', t => {
|
test('Valid CREATE transaction using sync', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -77,7 +71,6 @@ test('Valid CREATE transaction using sync', t => {
|
||||||
.then(resTx => t.truthy(resTx))
|
.then(resTx => t.truthy(resTx))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
const createTx = Transaction.makeCreateTransaction(
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
|
@ -107,7 +100,6 @@ test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
const createTx = Transaction.makeCreateTransaction(
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
|
@ -138,7 +130,6 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Valid TRANSFER transaction with multiple Ed25519 inputs from different transactions', t => {
|
test('Valid TRANSFER transaction with multiple Ed25519 inputs from different transactions', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
const carol = new Ed25519Keypair()
|
const carol = new Ed25519Keypair()
|
||||||
|
@ -202,6 +193,58 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs from different tra
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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 => {
|
test('Search for spent and unspent outputs of a given public key', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
const carol = new Ed25519Keypair()
|
const carol = new Ed25519Keypair()
|
||||||
|
@ -211,7 +254,6 @@ test('Search for spent and unspent outputs of a given public key', t => {
|
||||||
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
|
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
|
||||||
const trentOutput = Transaction.makeOutput(trentCondition)
|
const trentOutput = Transaction.makeOutput(trentCondition)
|
||||||
|
|
||||||
|
|
||||||
const createTx = Transaction.makeCreateTransaction(
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
asset(),
|
asset(),
|
||||||
metaData,
|
metaData,
|
||||||
|
@ -242,7 +284,6 @@ test('Search for spent and unspent outputs of a given public key', t => {
|
||||||
.then(outputs => t.truthy(outputs.length === 2))
|
.then(outputs => t.truthy(outputs.length === 2))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search for unspent outputs for a given public key', t => {
|
test('Search for unspent outputs for a given public key', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
const carol = new Ed25519Keypair()
|
const carol = new Ed25519Keypair()
|
||||||
|
@ -282,7 +323,6 @@ test('Search for unspent outputs for a given public key', t => {
|
||||||
.then(outputs => t.truthy(outputs.length === 2))
|
.then(outputs => t.truthy(outputs.length === 2))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search for spent outputs for a given public key', t => {
|
test('Search for spent outputs for a given public key', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
const carol = new Ed25519Keypair()
|
const carol = new Ed25519Keypair()
|
||||||
|
@ -322,7 +362,6 @@ test('Search for spent outputs for a given public key', t => {
|
||||||
.then(outputs => t.truthy(outputs.length === 1))
|
.then(outputs => t.truthy(outputs.length === 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search for an asset', t => {
|
test('Search for an asset', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -345,7 +384,6 @@ test('Search for an asset', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search for metadata', t => {
|
test('Search for metadata', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -368,7 +406,6 @@ test('Search for metadata', t => {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search blocks containing a transaction', t => {
|
test('Search blocks containing a transaction', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -390,7 +427,6 @@ test('Search blocks containing a transaction', t => {
|
||||||
.then(transactions => t.truthy(transactions.length === 1))
|
.then(transactions => t.truthy(transactions.length === 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search transaction containing an asset', t => {
|
test('Search transaction containing an asset', t => {
|
||||||
const conn = new Connection(API_PATH)
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
@ -412,7 +448,8 @@ test('Search transaction containing an asset', t => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Content-Type cannot be set', t => {
|
test('Content-Type cannot be set', t => {
|
||||||
t.throws(() => new Connection(API_PATH, { 'Content-Type': 'application/json' }), Error)
|
t.throws(() => new Connection(API_PATH, { 'Content-Type': 'application/json' }), {
|
||||||
|
instanceOf: Error
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import Connection from '../../src/connection'
|
import Connection from '../../src/connection'
|
||||||
|
|
||||||
|
|
||||||
const conn = new Connection()
|
const conn = new Connection()
|
||||||
|
|
||||||
test('Ensure that BackoffTimedelta works properly', t => {
|
test('Ensure that BackoffTimedelta works properly', t => {
|
||||||
|
@ -18,14 +17,10 @@ test('Ensure that BackoffTimedelta works properly', t => {
|
||||||
|
|
||||||
test('Ensure that updateBackoffTime throws and error on TimeoutError', async t => {
|
test('Ensure that updateBackoffTime throws and error on TimeoutError', async t => {
|
||||||
const req = conn.transport.pickConnection()
|
const req = conn.transport.pickConnection()
|
||||||
const target = {
|
const errorMessage = 'TimeoutError'
|
||||||
message: 'TimeoutError'
|
req.connectionError = new Error(errorMessage)
|
||||||
}
|
|
||||||
req.connectionError = target
|
|
||||||
|
|
||||||
const error = t.throws(() => {
|
t.throws(() => {
|
||||||
req.updateBackoffTime()
|
req.updateBackoffTime()
|
||||||
})
|
}, { instanceOf: Error, message: errorMessage })
|
||||||
|
|
||||||
t.deepEqual(target, error)
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,7 +9,6 @@ const sanitize = rewire('../../src/sanitize.js')
|
||||||
const applyFilterOnObject = sanitize.__get__('applyFilterOnObject')
|
const applyFilterOnObject = sanitize.__get__('applyFilterOnObject')
|
||||||
const filterFromObject = sanitize.__get__('filterFromObject')
|
const filterFromObject = sanitize.__get__('filterFromObject')
|
||||||
|
|
||||||
|
|
||||||
test('Ensure that null filter returns same object', t => {
|
test('Ensure that null filter returns same object', t => {
|
||||||
const expected = { 'testObj': 'test' }
|
const expected = { 'testObj': 'test' }
|
||||||
const actual = applyFilterOnObject({ 'testObj': 'test' }, null)
|
const actual = applyFilterOnObject({ 'testObj': 'test' }, null)
|
||||||
|
@ -17,7 +16,6 @@ test('Ensure that null filter returns same object', t => {
|
||||||
t.deepEqual(actual, expected)
|
t.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Ensure function filter with isInclusion true works properly', t => {
|
test('Ensure function filter with isInclusion true works properly', t => {
|
||||||
const testObj = [true, false, undefined, '', 0, null]
|
const testObj = [true, false, undefined, '', 0, null]
|
||||||
const expected = { 0: true }
|
const expected = { 0: true }
|
||||||
|
@ -26,7 +24,6 @@ test('Ensure function filter with isInclusion true works properly', t => {
|
||||||
t.deepEqual(actual, expected)
|
t.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Ensure function filter with isInclusion false works properly', t => {
|
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 testObj = [false, true, 1, 10, 'this will be removed as it is truthy']
|
||||||
const expected = { 0: false }
|
const expected = { 0: false }
|
||||||
|
@ -35,7 +32,6 @@ test('Ensure function filter with isInclusion false works properly', t => {
|
||||||
t.deepEqual(actual, expected)
|
t.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Ensure array filter with isInclusion true works properly', t => {
|
test('Ensure array filter with isInclusion true works properly', t => {
|
||||||
const testObj = [true, false, undefined, '', 0, null]
|
const testObj = [true, false, undefined, '', 0, null]
|
||||||
const expected = { 0: true }
|
const expected = { 0: true }
|
||||||
|
@ -44,7 +40,6 @@ test('Ensure array filter with isInclusion true works properly', t => {
|
||||||
t.deepEqual(actual, expected)
|
t.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Ensure array filter with isInclusion false works properly', t => {
|
test('Ensure array filter with isInclusion false works properly', t => {
|
||||||
const testObj = [false, true, 1, 10]
|
const testObj = [false, true, 1, 10]
|
||||||
const expected = { 0: false }
|
const expected = { 0: false }
|
||||||
|
@ -53,12 +48,8 @@ test('Ensure array filter with isInclusion false works properly', t => {
|
||||||
t.deepEqual(actual, expected)
|
t.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Ensure throws error when given invalid filter', t => {
|
test('Ensure throws error when given invalid filter', t => {
|
||||||
const error = t.throws(() => {
|
t.throws(() => {
|
||||||
filterFromObject({}, 'lol')
|
filterFromObject({}, 'lol')
|
||||||
}, Error)
|
}, { instanceOf: Error, message: 'The given filter is not an array or function. Filter aborted' })
|
||||||
|
|
||||||
t.is(error.message, 'The given filter is not an array or function. Filter aborted')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,10 @@ test('formatText test type 3', t => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('formatText test throws', t => {
|
test('formatText test throws', t => {
|
||||||
const error = t.throws(() => {
|
t.throws(() => {
|
||||||
formatText(
|
formatText(
|
||||||
'This will give ${error.}', // eslint-disable-line no-template-curly-in-string
|
'This will give ${error.}', // eslint-disable-line no-template-curly-in-string
|
||||||
{ error: [{}] }
|
{ error: [{}] }
|
||||||
)
|
)
|
||||||
}, SyntaxError)
|
}, { instanceOf: SyntaxError, message: '[formatText] failed to parse named argument key: error.' })
|
||||||
|
|
||||||
t.is(error.message, '[formatText] failed to parse named argument key: error.')
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are 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 test from 'ava'
|
||||||
import cc from 'crypto-conditions'
|
import base58 from 'bs58'
|
||||||
import { Ed25519Keypair, Transaction, ccJsonLoad } from '../../src'
|
import { Ed25519Keypair, Transaction, ccJsonLoad } from '../../src'
|
||||||
|
import { delegatedSignTransaction } from '../constants'
|
||||||
import sha256Hash from '../../src/sha256Hash'
|
import sha256Hash from '../../src/sha256Hash'
|
||||||
|
|
||||||
test('Ed25519 condition encoding', t => {
|
test('Ed25519 condition encoding', t => {
|
||||||
|
@ -33,7 +36,6 @@ test('Sha256Condition fulfillment', t => {
|
||||||
t.deepEqual(target, Transaction.makeSha256Condition(preimage))
|
t.deepEqual(target, Transaction.makeSha256Condition(preimage))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Threshold condition encoding', t => {
|
test('Threshold condition encoding', t => {
|
||||||
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
||||||
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
|
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
|
||||||
|
@ -63,7 +65,6 @@ test('Threshold condition encoding', t => {
|
||||||
t.deepEqual(target, output)
|
t.deepEqual(target, output)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Fulfillment correctly formed', t => {
|
test('Fulfillment correctly formed', t => {
|
||||||
const alice = new Ed25519Keypair()
|
const alice = new Ed25519Keypair()
|
||||||
const txCreate = Transaction.makeCreateTransaction(
|
const txCreate = Transaction.makeCreateTransaction(
|
||||||
|
@ -90,39 +91,60 @@ test('Fulfillment correctly formed', t => {
|
||||||
.concat(txTransfer.inputs[0].fulfills.output_index) : msg
|
.concat(txTransfer.inputs[0].fulfills.output_index) : msg
|
||||||
const msgHash = sha256Hash(msgUniqueFulfillment)
|
const msgHash = sha256Hash(msgUniqueFulfillment)
|
||||||
|
|
||||||
t.truthy(cc.validateFulfillment(
|
t.truthy(validateFulfillment(
|
||||||
txSigned.inputs[0].fulfillment, txCreate.outputs[0].condition.uri,
|
txSigned.inputs[0].fulfillment,
|
||||||
|
txCreate.outputs[0].condition.uri,
|
||||||
Buffer.from(msgHash, 'hex')
|
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 => {
|
test('CryptoConditions JSON load', t => {
|
||||||
|
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
||||||
const cond = ccJsonLoad({
|
const cond = ccJsonLoad({
|
||||||
type: 'threshold-sha-256',
|
type: 'threshold-sha-256',
|
||||||
threshold: 1,
|
threshold: 1,
|
||||||
subconditions: [{
|
subconditions: [{
|
||||||
type: 'ed25519-sha-256',
|
type: 'ed25519-sha-256',
|
||||||
public_key: 'a'
|
public_key: publicKey
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hash: 'a'
|
hash: base58.encode(createHash('sha256').update('a').digest())
|
||||||
}],
|
|
||||||
})
|
|
||||||
t.truthy(cond.subconditions.length === 2)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test('CryptoConditions JSON load', t => {
|
|
||||||
const cond = ccJsonLoad({
|
|
||||||
type: 'threshold-sha-256',
|
|
||||||
threshold: 1,
|
|
||||||
subconditions: [{
|
|
||||||
type: 'ed25519-sha-256',
|
|
||||||
public_key: 'a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
hash: 'a'
|
|
||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
t.truthy(cond.subconditions.length === 2)
|
t.truthy(cond.subconditions.length === 2)
|
||||||
|
|
|
@ -15,7 +15,6 @@ import {
|
||||||
transferTx
|
transferTx
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
|
|
||||||
|
|
||||||
test('Create valid output with default amount', t => {
|
test('Create valid output with default amount', t => {
|
||||||
const condition = {
|
const condition = {
|
||||||
details: {
|
details: {
|
||||||
|
@ -32,7 +31,6 @@ test('Create valid output with default amount', t => {
|
||||||
t.deepEqual(res, expected)
|
t.deepEqual(res, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Create valid output with custom amount', t => {
|
test('Create valid output with custom amount', t => {
|
||||||
const condition = {
|
const condition = {
|
||||||
details: {
|
details: {
|
||||||
|
@ -65,12 +63,10 @@ test('Pass condition not based on public_keys to makeOutput', t => {
|
||||||
t.deepEqual(res, expected)
|
t.deepEqual(res, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('makeOutput throws TypeError with incorrect amount type', t => {
|
test('makeOutput throws TypeError with incorrect amount type', t => {
|
||||||
t.throws(() => Transaction.makeOutput({}, 1337), TypeError)
|
t.throws(() => Transaction.makeOutput({}, 1337), { instanceOf: TypeError })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Create TRANSFER transaction based on CREATE transaction', t => {
|
test('Create TRANSFER transaction based on CREATE transaction', t => {
|
||||||
sinon.spy(Transaction, 'makeTransaction')
|
sinon.spy(Transaction, 'makeTransaction')
|
||||||
Transaction.makeTransferTransaction(
|
Transaction.makeTransferTransaction(
|
||||||
|
@ -95,7 +91,6 @@ test('Create TRANSFER transaction based on CREATE transaction', t => {
|
||||||
Transaction.makeTransaction.restore()
|
Transaction.makeTransaction.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Create TRANSFER transaction based on TRANSFER transaction', t => {
|
test('Create TRANSFER transaction based on TRANSFER transaction', t => {
|
||||||
sinon.spy(Transaction, 'makeTransaction')
|
sinon.spy(Transaction, 'makeTransaction')
|
||||||
|
|
||||||
|
|
10
types/Ed25519Keypair.d.ts
vendored
Normal file
10
types/Ed25519Keypair.d.ts
vendored
Normal 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
31
types/baseRequest.d.ts
vendored
Normal 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
179
types/connection.d.ts
vendored
Normal 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
39
types/index.d.ts
vendored
Normal 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
32
types/request.d.ts
vendored
Normal 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
25
types/sanitize.d.ts
vendored
Normal 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
236
types/transaction.d.ts
vendored
Normal 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
21
types/transport.d.ts
vendored
Normal 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
32
types/utils/ccJsonLoad.d.ts
vendored
Normal 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
70
types/utils/ccJsonify.d.ts
vendored
Normal 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;
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { paths } = require('./webpack.parts.js')
|
const { ProvidePlugin } = require('webpack')
|
||||||
|
const { paths } = require('./webpack.parts')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: paths.entry,
|
entry: paths.entry,
|
||||||
|
@ -24,10 +25,18 @@ module.exports = {
|
||||||
},
|
},
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: true,
|
minimize: true,
|
||||||
noEmitOnErrors: true
|
emitOnErrors: false
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js'],
|
extensions: ['.js'],
|
||||||
modules: ['node_modules'],
|
modules: ['node_modules'],
|
||||||
|
fallback: {
|
||||||
|
buffer: require.resolve('buffer/'),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new ProvidePlugin({
|
||||||
|
Buffer: ['buffer', 'Buffer']
|
||||||
|
})
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
const PRODUCTION = process.env.NODE_ENV === 'production'
|
const PRODUCTION = process.env.NODE_ENV === 'production'
|
||||||
|
|
||||||
const common = require('./webpack.common.js')
|
const common = require('./webpack.common')
|
||||||
|
|
||||||
const { outputs } = require('./webpack.parts.js')
|
const { outputs } = require('./webpack.parts')
|
||||||
|
|
||||||
// '[libraryTarget]': [file extension]
|
// '[libraryTarget]': [file extension]
|
||||||
const OUTPUT_MAPPING = {
|
const OUTPUT_MAPPING = {
|
||||||
|
|
|
@ -2,23 +2,21 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
/* eslint-disable strict, no-console, object-shorthand */
|
/* eslint-disable strict, no-console, object-shorthand, import/no-extraneous-dependencies */
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
const TerserPlugin = require('terser-webpack-plugin')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
devtool: 'inline-source-map',
|
devtool: 'inline-source-map',
|
||||||
optimization: {
|
optimization: {
|
||||||
minimizer: [
|
minimizer: [
|
||||||
new UglifyJsPlugin({
|
new TerserPlugin({
|
||||||
test: /vendor/,
|
test: /vendor/,
|
||||||
sourceMap: false,
|
|
||||||
}),
|
}),
|
||||||
new UglifyJsPlugin({
|
new TerserPlugin({
|
||||||
test: /^((?!(vendor)).)*.js$/,
|
test: /^((?!(vendor)).)*.js$/,
|
||||||
sourceMap: true,
|
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
splitChunks: {
|
splitChunks: {
|
||||||
|
@ -29,6 +27,6 @@ module.exports = {
|
||||||
chunks: 'all'
|
chunks: 'all'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
// Code is Apache-2.0 and docs are CC-BY-4.0
|
// Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
/* eslint-disable strict, no-console, object-shorthand */
|
/* eslint-disable strict, no-console, object-shorthand, import/no-extraneous-dependencies */
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const merge = require('webpack-merge')
|
const { merge } = require('webpack-merge')
|
||||||
|
|
||||||
const development = require('./webpack.development.js')
|
const development = require('./webpack.development')
|
||||||
const production = require('./webpack.production.js')
|
const production = require('./webpack.production')
|
||||||
|
|
||||||
const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
|
const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user