Socket
Socket
Sign inDemoInstall

bigchaindb-driver

Package Overview
Dependencies
Maintainers
6
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bigchaindb-driver - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

dist/browser/bigchaindb-driver.amd.js

424

API.md

@@ -5,69 +5,175 @@ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->

- [Ed25519Keypair](#ed25519keypair)
- [makeEd25519Condition](#makeed25519condition)
- [makeSha256Condition](#makesha256condition)
- [makeThresholdCondition](#makethresholdcondition)
- [makeCreateTransaction](#makecreatetransaction)
- [makeOutput](#makeoutput)
- [makeTransferTransaction](#maketransfertransaction)
- [serializeTransactionIntoCanonicalString](#serializetransactionintocanonicalstring)
- [signTransaction](#signtransaction)
- [ccJsonLoad](#ccjsonload)
- [ccJsonify](#ccjsonify)
- [getBlock](#getblock)
- [getStatus](#getstatus)
- [getTransaction](#gettransaction)
- [listBlocks](#listblocks)
- [listOutputs](#listoutputs)
- [listTransactions](#listtransactions)
- [listVotes](#listvotes)
- [pollStatusAndFetchTransaction](#pollstatusandfetchtransaction)
- [postTransaction](#posttransaction)
- [Ed25519Keypair][1]
- [Connection][2]
- [getBlock][3]
- [getTransaction][4]
- [listBlocks][5]
- [listOutputs][6]
- [listTransactions][7]
- [listVotes][8]
- [postTransaction][9]
- [postTransactionSync][10]
- [postTransactionCommit][11]
- [searchAssets][12]
- [searchMetadata][13]
- [Transaction][14]
- [serializeTransactionIntoCanonicalString][15]
- [makeCreateTransaction][16]
- [makeEd25519Condition][17]
- [makeOutput][18]
- [makeSha256Condition][19]
- [makeThresholdCondition][20]
- [makeTransferTransaction][21]
- [signTransaction][22]
- [ccJsonLoad][23]
- [ccJsonify][24]
## Ed25519Keypair
[src/Ed25519Keypair.js:12-17][25]
Type: [Object][26]
**Parameters**
- `secret` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** A seed that will be used as a key derivation function
- `seed` **[Buffer][27]?** A seed that will be used as a key derivation function
**Properties**
- `publicKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `privateKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `publicKey` **[string][28]**
- `privateKey` **[string][28]**
## makeEd25519Condition
## Connection
[src/connection.js:8-168][29]
Base connection
**Parameters**
- `publicKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** base58 encoded Ed25519 public key for the recipient of the Transaction
- `json` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
- `path`
- `headers` (optional, default `{}`)
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Ed25519 Condition (that will need to wrapped in an Output)
### getBlock
## makeSha256Condition
[src/connection.js:44-50][30]
**Parameters**
- `preimage` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Preimage to be hashed and wrapped in a crypto-condition
- `json` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
- `blockHeight`
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Preimage-Sha256 Condition (that will need to wrapped in an Output)
### getTransaction
## makeThresholdCondition
[src/connection.js:55-61][31]
**Parameters**
- `threshold` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `subconditions` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** (optional, default `[]`)
- `json` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
- `transactionId`
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Sha256 Threshold Condition (that will need to wrapped in an Output)
### listBlocks
## makeCreateTransaction
[src/connection.js:67-73][32]
**Parameters**
- `asset` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Created asset's data
- `metadata` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Metadata for the Transaction
- `outputs` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** Array of Output objects to add to the Transaction.
- `transactionId`
- `status`
### listOutputs
[src/connection.js:79-91][33]
**Parameters**
- `publicKey`
- `spent`
### listTransactions
[src/connection.js:97-104][34]
**Parameters**
- `assetId`
- `operation`
### listVotes
[src/connection.js:109-115][35]
**Parameters**
- `blockId`
### postTransaction
[src/connection.js:120-125][36]
**Parameters**
- `transaction`
### postTransactionSync
[src/connection.js:130-135][37]
**Parameters**
- `transaction`
### postTransactionCommit
[src/connection.js:140-145][38]
**Parameters**
- `transaction`
### searchAssets
[src/connection.js:150-156][39]
**Parameters**
- `search`
### searchMetadata
[src/connection.js:161-167][40]
**Parameters**
- `search`
## Transaction
[src/transaction.js:12-253][41]
Construct Transactions
### serializeTransactionIntoCanonicalString
[src/transaction.js:18-25][42]
Canonically serializes a transaction into a string by sorting the keys
**Parameters**
- `transaction`
- `null` **[Object][26]** (transaction)
Returns **[string][28]** a canonically serialized Transaction
### makeCreateTransaction
[src/transaction.js:76-83][43]
Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
the `issuers`.
**Parameters**
- `asset` **[Object][26]** Created asset's data
- `metadata` **[Object][26]** Metadata for the Transaction
- `outputs` **[Array][44]&lt;[Object][26]>** Array of Output objects to add to the Transaction.
Think of these as the recipients of the asset after the transaction.

@@ -77,3 +183,3 @@ For `CREATE` Transactions, this should usually just be a list of

keys (so that the issuers are the recipients of the created asset).
- `issuers` **...[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Public key of one or more issuers to the asset being created by this
- `issuers` **...[Array][44]&lt;[string][28]>** Public key of one or more issuers to the asset being created by this
Transaction.

@@ -84,22 +190,72 @@ Note: Each of the private keys corresponding to the given public

Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Unsigned transaction -- make sure to call signTransaction() on it before
Returns **[Object][26]** Unsigned transaction -- make sure to call signTransaction() on it before
sending it off!
## makeOutput
### makeEd25519Condition
[src/transaction.js:92-103][45]
Create an Ed25519 Cryptocondition from an Ed25519 public key
to put into an Output of a Transaction
**Parameters**
- `condition` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
- `amount` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Amount of the output (optional, default `1`)
- `publicKey` **[string][28]** base58 encoded Ed25519 public key for the recipient of the Transaction
- `json` **[boolean][46]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** An Output usable in a Transaction
Returns **[Object][26]** Ed25519 Condition (that will need to wrapped in an Output)
## makeTransferTransaction
### makeOutput
[src/transaction.js:113-133][47]
Create an Output from a Condition.
Note: Assumes the given Condition was generated from a
single public key (e.g. a Ed25519 Condition)
**Parameters**
- `unspentTransaction` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Previous Transaction you have control over (i.e. can fulfill
its Output Condition)
- `metadata` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Metadata for the Transaction
- `outputs` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** Array of Output objects to add to the Transaction.
- `condition` **[Object][26]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
- `amount` **[string][28]** Amount of the output (optional, default `'1'`)
Returns **[Object][26]** An Output usable in a Transaction
### makeSha256Condition
[src/transaction.js:141-149][48]
Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
**Parameters**
- `preimage` **[string][28]** Preimage to be hashed and wrapped in a crypto-condition
- `json` **[boolean][46]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][26]** Preimage-Sha256 Condition (that will need to wrapped in an Output)
### makeThresholdCondition
[src/transaction.js:158-172][49]
Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
**Parameters**
- `threshold` **[number][50]**
- `subconditions` **[Array][44]** (optional, default `[]`)
- `json` **[boolean][46]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][26]** Sha256 Threshold Condition (that will need to wrapped in an Output)
### makeTransferTransaction
[src/transaction.js:195-216][51]
Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
the `fulfilledOutputs` of `unspentTransaction`.
**Parameters**
- `unspentOutputs`
- `outputs` **[Array][44]&lt;[Object][26]>** Array of Output objects to add to the Transaction.
Think of these as the recipients of the asset after the transaction.

@@ -109,36 +265,41 @@ For `TRANSFER` Transactions, this should usually just be a list of

the recipients.
- `fulfilledOutputs` **...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Indices of the Outputs in `unspentTransaction` that this
- `metadata` **[Object][26]** Metadata for the Transaction
- `unspentTransaction` **[Object][26]** Previous Transaction you have control over (i.e. can fulfill
its Output Condition)
- `OutputIndices` **...[number][50]** Indices of the Outputs in `unspentTransaction` that this
Transaction fulfills.
Note that the public keys listed in the fulfilled Outputs
must be used (and in the same order) to sign the Transaction
Note that listed public keys listed must be used (and in
the same order) to sign the Transaction
(`signTransaction()`).
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Unsigned transaction -- make sure to call signTransaction() on it before
Returns **[Object][26]** Unsigned transaction -- make sure to call signTransaction() on it before
sending it off!
## serializeTransactionIntoCanonicalString
### signTransaction
**Parameters**
[src/transaction.js:229-252][52]
- `transaction`
- `null` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** (transaction)
Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
that's been signed.
Note: Only generates Ed25519 Fulfillments. Thresholds and other types of Fulfillments are left as
an exercise for the user.
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** a canonically serialized Transaction
## signTransaction
**Parameters**
- `transaction` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Private keys associated with the issuers of the `transaction`.
- `transaction` **[Object][26]** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string][28]** Private keys associated with the issuers of the `transaction`.
Looped through to iteratively sign any Input Fulfillments found in
the `transaction`.
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The signed version of `transaction`.
Returns **[Object][26]** The signed version of `transaction`.
## ccJsonLoad
[src/utils/ccJsonLoad.js:10-40][53]
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
**Parameters**
- `conditionJson` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `conditionJson` **[Object][26]**

@@ -149,75 +310,118 @@ Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)

[src/utils/ccJsonify.js:8-61][54]
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
**Parameters**
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for the recipient of the Transaction
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Ed25519 Condition (that will need to wrapped in an Output)
Returns **[Object][26]** Ed25519 Condition (that will need to wrapped in an Output)
## getBlock
[1]: #ed25519keypair
**Parameters**
[2]: #connection
- `blockId`
[3]: #getblock
## getStatus
[4]: #gettransaction
**Parameters**
[5]: #listblocks
- `tx_id`
[6]: #listoutputs
## getTransaction
[7]: #listtransactions
**Parameters**
[8]: #listvotes
- `txId`
[9]: #posttransaction
## listBlocks
[10]: #posttransactionsync
**Parameters**
[11]: #posttransactioncommit
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.tx_id`
- `$0.status`
- `tx_id`
- `status`
[12]: #searchassets
## listOutputs
[13]: #searchmetadata
**Parameters**
[14]: #transaction
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.public_key`
- `$0.unspent`
- `onlyJsonResponse`
- `public_key`
- `unspent`
[15]: #serializetransactionintocanonicalstring
## listTransactions
[16]: #makecreatetransaction
**Parameters**
[17]: #makeed25519condition
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.asset_id`
- `$0.operation`
- `asset_id`
- `operation`
[18]: #makeoutput
## listVotes
[19]: #makesha256condition
**Parameters**
[20]: #makethresholdcondition
- `block_id`
[21]: #maketransfertransaction
## pollStatusAndFetchTransaction
[22]: #signtransaction
**Parameters**
[23]: #ccjsonload
- `tx_id`
[24]: #ccjsonify
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
[25]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/Ed25519Keypair.js#L12-L17 "Source code on GitHub"
## postTransaction
[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
**Parameters**
[27]: https://nodejs.org/api/buffer.html
- `transaction`
[28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[29]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L8-L168 "Source code on GitHub"
[30]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L44-L50 "Source code on GitHub"
[31]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L55-L61 "Source code on GitHub"
[32]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L67-L73 "Source code on GitHub"
[33]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L79-L91 "Source code on GitHub"
[34]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L97-L104 "Source code on GitHub"
[35]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L109-L115 "Source code on GitHub"
[36]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L120-L125 "Source code on GitHub"
[37]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L130-L135 "Source code on GitHub"
[38]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L140-L145 "Source code on GitHub"
[39]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L150-L156 "Source code on GitHub"
[40]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/connection.js#L161-L167 "Source code on GitHub"
[41]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L12-L253 "Source code on GitHub"
[42]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L18-L25 "Source code on GitHub"
[43]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L76-L83 "Source code on GitHub"
[44]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[45]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L92-L103 "Source code on GitHub"
[46]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[47]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L113-L133 "Source code on GitHub"
[48]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L141-L149 "Source code on GitHub"
[49]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L158-L172 "Source code on GitHub"
[50]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[51]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L195-L216 "Source code on GitHub"
[52]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/transaction.js#L229-L252 "Source code on GitHub"
[53]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/utils/ccJsonLoad.js#L10-L40 "Source code on GitHub"
[54]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/utils/ccJsonify.js#L8-L61 "Source code on GitHub"

@@ -34,2 +34,3 @@ 'use strict';

/**
* @private
* imported from https://github.com/bigchaindb/js-utility-belt/

@@ -48,10 +49,10 @@ *

* `config.urlTemplateSpec`.
* @param {object} config Additional configuration, mostly passed to fetch as its 'init' config
* @param {Object} config Additional configuration, mostly passed to fetch as its 'init' config
* (see https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch#Parameters).
* @param {*} config.jsonBody Json payload to the request. Will automatically be
* JSON.stringify()-ed and override `config.body`.
* @param {string|object} config.query Query parameter to append to the end of the url.
* @param {string|Object} config.query Query parameter to append to the end of the url.
* If specified as an object, keys will be
* decamelized into snake case first.
* @param {*[]|object} config.urlTemplateSpec Format spec to use to expand the url (see sprintf).
* @param {*[]|Object} config.urlTemplateSpec Format spec to use to expand the url (see sprintf).
* @param {*} config.* All other options are passed through to fetch.

@@ -58,0 +59,0 @@ *

@@ -21,2 +21,6 @@ 'use strict';

/**
* Base connection
*/
var Connection = function () {

@@ -65,3 +69,2 @@ function Connection(path) {

/**
* @public
* @param blockHeight

@@ -81,3 +84,2 @@ */

/**
* @public
* @param transactionId

@@ -97,3 +99,2 @@ */

/**
* @public
* @param transactionId

@@ -114,3 +115,2 @@ * @param status

/**
* @public
* @param publicKey

@@ -136,3 +136,2 @@ * @param spent

/**
* @public
* @param assetId

@@ -154,3 +153,2 @@ * @param operation

/**
* @public
* @param blockId

@@ -170,3 +168,2 @@ */

/**
* @public
* @param transaction

@@ -185,3 +182,2 @@ */

/**
* @public
* @param transaction

@@ -200,3 +196,2 @@ */

/**
* @public
* @param transaction

@@ -209,3 +204,2 @@ */

return this._req(this.getApiUrls('transactionsCommit'), {
method: 'POST',

@@ -217,3 +211,2 @@ jsonBody: transaction

/**
* @public
* @param search

@@ -233,3 +226,2 @@ */

/**
* @public
* @param search

@@ -236,0 +228,0 @@ */

@@ -20,3 +20,3 @@ 'use strict';

* @public
* @class Keypair Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* @type {Object}

@@ -23,0 +23,0 @@ * @param {Buffer} [seed] A seed that will be used as a key derivation function

@@ -22,3 +22,3 @@ 'use strict';

* imported from https://github.com/bigchaindb/js-utility-belt/
*
* @private
* Formats strings similarly to C's sprintf, with the addition of '${...}' formats.

@@ -64,2 +64,3 @@ *

/**
* @private
* Interpolation algorithm inspired by sprintf-js.

@@ -66,0 +67,0 @@ *

@@ -27,2 +27,3 @@ 'use strict';

/**
* @private
* Small wrapper around js-utility-belt's request that provides url resolving,

@@ -29,0 +30,0 @@ * default settings, and response handling.

@@ -24,2 +24,3 @@ 'use strict';

/**
* @private
* Abstraction for selectFromObject and omitFromObject for DRYness.

@@ -51,2 +52,3 @@ * Set isInclusion to true if the filter should be for including the filtered items (ie. selecting

/**
* @private
* Returns a filtered copy of the given object's own enumerable properties (no inherited

@@ -75,8 +77,9 @@ * properties), keeping any keys that pass the given filter function.

/**
* @private
* Similar to lodash's _.pick(), this returns a copy of the given object's
* own and inherited enumerable properties, selecting only the keys in
* the given array or whose value pass the given filter function.
* @param {object} obj Source object
* @param {array|function} filter Array of key names to select or function to invoke per iteration
* @return {object} The new object
* @param {Object} obj Source object
* @param {Array|function} filter Array of key names to select or function to invoke per iteration
* @return {Object} The new object
*/

@@ -88,2 +91,3 @@ function selectFromObject(obj, filter) {

/**
* @private
* Glorified selectFromObject. Takes an object and returns a filtered shallow copy that strips out

@@ -93,4 +97,4 @@ * any properties that are falsy (including coercions, ie. undefined, null, '', 0, ...).

*
* @param {object} obj Javascript object
* @return {object} Sanitized Javascript object
* @param {Object} obj Javascript object
* @return {Object} Sanitized Javascript object
*/

@@ -97,0 +101,0 @@ function sanitize(obj) {

@@ -28,2 +28,3 @@ 'use strict';

/**
* @private
* imported from https://github.com/bigchaindb/js-utility-belt/

@@ -49,3 +50,3 @@ *

*
* @param {object} obj Query params dictionary
* @param {Object} obj Query params dictionary
* @param {function} [transform=decamelize] Transform function for each of the param keys

@@ -52,0 +53,0 @@ * @return {string} Query param string

@@ -39,2 +39,5 @@ 'use strict';

/**
* Construct Transactions
*/
var Transaction = function () {

@@ -49,5 +52,4 @@ function Transaction() {

/**
* @public
* Canonically serializes a transaction into a string by sorting the keys
* @param {object} (transaction)
* @param {Object} (transaction)
* @return {string} a canonically serialized Transaction

@@ -109,8 +111,7 @@ */

/**
* @public
* Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
* the `issuers`.
* @param {object} asset Created asset's data
* @param {object} metadata Metadata for the Transaction
* @param {object[]} outputs Array of Output objects to add to the Transaction.
* @param {Object} asset Created asset's data
* @param {Object} metadata Metadata for the Transaction
* @param {Object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.

@@ -125,3 +126,3 @@ * For `CREATE` Transactions, this should usually just be a list of

* Transaction (`signTransaction()`).
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
* @returns {Object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!

@@ -149,3 +150,2 @@ */

/**
* @public
* Create an Ed25519 Cryptocondition from an Ed25519 public key

@@ -155,3 +155,3 @@ * to put into an Output of a Transaction

* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output)
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/

@@ -177,9 +177,8 @@

/**
* @public
* Create an Output from a Condition.
* Note: Assumes the given Condition was generated from a
* single public key (e.g. a Ed25519 Condition)
* @param {object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {Object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {string} amount Amount of the output
* @returns {object} An Output usable in a Transaction
* @returns {Object} An Output usable in a Transaction
*/

@@ -214,7 +213,6 @@

/**
* @public
* Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
* @param {string} preimage Preimage to be hashed and wrapped in a crypto-condition
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
*/

@@ -237,3 +235,2 @@

/**
* @public
* Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction

@@ -243,3 +240,3 @@ * @param {number} threshold

* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Sha256 Threshold Condition (that will need to wrapped in an Output)
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
*/

@@ -269,9 +266,8 @@

/**
* @public
* Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
* the `fulfilledOutputs` of `unspentTransaction`.
* @param {object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
* @param {Object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
* its Output Condition)
* @param {object} metadata Metadata for the Transaction
* @param {object[]} outputs Array of Output objects to add to the Transaction.
* @param {Object} metadata Metadata for the Transaction
* @param {Object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.

@@ -286,3 +282,3 @@ * For `TRANSFER` Transactions, this should usually just be a list of

* (`signTransaction()`).
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
* @returns {Object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!

@@ -317,3 +313,2 @@ */

/**
* @public
* Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`

@@ -323,7 +318,7 @@ * that's been signed.

* an exercise for the user.
* @param {object} transaction Transaction to sign. `transaction` is not modified.
* @param {Object} transaction Transaction to sign. `transaction` is not modified.
* @param {...string} privateKeys Private keys associated with the issuers of the `transaction`.
* Looped through to iteratively sign any Input Fulfillments found in
* the `transaction`.
* @returns {object} The signed version of `transaction`.
* @returns {Object} The signed version of `transaction`.
*/

@@ -330,0 +325,0 @@

@@ -15,6 +15,5 @@ 'use strict';

/**
* @public
* Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
* @param {cc.Fulfillment} fulfillment base58 encoded Ed25519 public key for recipient of the Transaction
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output)
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/

@@ -21,0 +20,0 @@ function ccJsonify(fulfillment) {

@@ -21,5 +21,4 @@ 'use strict';

/**
* @public
* Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
* @param {object} conditionJson
* @param {Object} conditionJson
* @returns {cc.Condition} Ed25519 Condition (that will need to wrapped in an Output)

@@ -26,0 +25,0 @@ */

{
"name": "bigchaindb-driver",
"version": "4.0.0",
"version": "4.0.1",
"description": "Node.js driver for BigchainDB",

@@ -16,3 +16,3 @@ "homepage": "https://www.bigchaindb.com/",

"scripts": {
"lint": "eslint ./",
"lint": "eslint ./{src,test,examples}",
"build": "npm run clean && npm run build:cjs && npm run build:dist",

@@ -22,5 +22,5 @@ "build:bundle": "webpack",

"build:dist": "cross-env NODE_ENV=production webpack -p",
"dev": "webpack -p -w",
"clean": "rimraf dist/bundle dist/node",
"test": "npm run lint && nyc ava test/ && npm run thanks && npm run report-coverage",
"testmine": "npm run lint && nyc ava test/integration/test_min*",
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",

@@ -32,3 +32,4 @@ "release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",

"precommit": "lint-staged",
"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"
},

@@ -55,2 +56,3 @@ "lint-staged": {

"cross-env": "^5.1.4",
"documentation": "^6.3.2",
"eslint": "^4.19.1",

@@ -61,7 +63,7 @@ "eslint-config-ascribe": "^3.0.5",

"lint-staged": "^7.0.0",
"sinon": "^5.0.0",
"nyc": "^11.6.0",
"release-it": "^7.2.1",
"rimraf": "^2.6.2",
"webpack": "^4.4.1",
"sinon": "^5.0.0",
"webpack": "^4.8.3",
"webpack-cli": "^2.0.13"

@@ -68,0 +70,0 @@ },

# [![js-bigchaindb-driver](media/repo-banner@2x.png)](https://www.bigchaindb.com)
> Official JavaScript driver for [BigchainDB](https://github.com/bigchaindb/bigchaindb) with some naive helpers to get you on your way making transactions in Node.js and the browser.
> Official JavaScript driver for [BigchainDB](https://github.com/bigchaindb/bigchaindb) to create transactions in Node.js and the browser.

@@ -12,3 +12,4 @@ [![Join the chat at https://gitter.im/bigchaindb/js-bigchaindb-driver](https://badges.gitter.im/bigchaindb/js-bigchaindb-driver.svg)](https://gitter.im/bigchaindb/js-bigchaindb-driver?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

- Documentation: https://docs.bigchaindb.com/projects/js-driver/en/latest/usage.html
- [Main Documentation](https://docs.bigchaindb.com/projects/js-driver/en/latest/usage.html)
- [Driver API reference](API.md)

@@ -20,19 +21,26 @@ ## Compatibility

| `0.10` | `0.1.x` |
| `1.0.0` | `0.3.x` |
| `>= 1.3.0` | `3.x.x` |
| `1.0.0` | `0.3.x` |
| `1.3.x` | `3.x.x` |
| `>= 2.0.0` | `4.x.x` |
## Breaking changes
Version 3.2 of BigchainDB JavaScript Driver introduces a new way of creating transfer transactions. Check [older versions](https://docs.bigchaindb.com/projects/js-driver/en/latest/readme.html#features)
## Contents
- **Version 4.0** of BigchainDB JavaScript Driver makes the driver compatible with BigchainDB 2.0. There are new functions for sending off transactions along with other changes. Check [older versions](https://docs.bigchaindb.com/projects/js-driver/en/latest/readme.html#features)
- **Version 3.2** of BigchainDB JavaScript Driver introduces a new way of creating transfer transactions. Check [older versions](https://docs.bigchaindb.com/projects/js-driver/en/latest/readme.html#features)
* [Installation and Usage with package managers (npm/yarn)](#installation-and-usage-with-package-managers-npmyarn)
* [Example: Create a transaction](#example-create-a-transaction)
* [Use a pre-built image (browser only)](#use-a-pre-built-image-browser-only)
* [Documentation](#bigchaindb-documentation)
* [Authors](#authors)
* [License](#license)
## Table of Contents
## Installation and Usage with package managers (npm/yarn)
- [Installation and Usage](#installation-and-usage)
- [Example: Create a transaction](#example-create-a-transaction)
- [Browser usage](#browser-usage)
- [BigchainDB Documentation](#bigchaindb-documentation)
- [Speed Optimizations](#speed-optimizations)
- [Development](#development)
- [Authors](#authors)
- [License](#license)
---
## Installation and Usage
```bash

@@ -42,2 +50,8 @@ npm install bigchaindb-driver

```js
const driver = require('bigchaindb-driver')
// or ES6+
import driver from 'bigchaindb-driver'
```
### Example: Create a transaction

@@ -48,3 +62,3 @@

// BigchainDB server instance or IPDB (e.g. https://test.ipdb.io/api/v1/)
// BigchainDB server instance (e.g. https://test.bigchaindb.com/api/v1/)
const API_PATH = 'http://localhost:9984/api/v1/'

@@ -78,8 +92,7 @@

conn.postTransaction(txSigned)
.then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
conn.postTransactionCommit(txSigned)
.then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.'))
```
## Use a pre-built image (browser only)
### Browser usage

@@ -93,6 +106,6 @@ ```html

<!-- Adjust version to your needs -->
<script src="https://unpkg.com/bigchaindb-driver@0.3.0/dist/browser/bigchaindb-driver.window.min.js"></script>
<script src="https://unpkg.com/bigchaindb-driver@4.0.0/dist/browser/bigchaindb-driver.window.min.js"></script>
<script>
// BigchainDB server instance or IPDB (e.g. https://test.ipdb.io/api/v1/)
// BigchainDB server instance (e.g. https://test.bigchaindb.com/api/v1/)
const API_PATH = 'http://localhost:9984/api/v1/'

@@ -126,4 +139,3 @@

conn.postTransaction(txSigned)
.then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
conn.postTransactionCommit(txSigned)
.then(res => {

@@ -147,2 +159,3 @@ const elem = document.getElementById('lastTransaction')

- [The Hitchhiker's Guide to BigchainDB](https://www.bigchaindb.com/developers/guide/)
- [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html)

@@ -161,3 +174,18 @@ - [The Transaction Model](https://docs.bigchaindb.com/projects/server/en/latest/data-models/transaction-model.html?highlight=crypto%20conditions)

## Development
```js
git clone git@github.com:bigchaindb/js-bigchaindb-driver.git
cd js-bigchaindb-driver/
npm i
npm run dev
```
After updating source files in `src/`, make sure to update the API documentation. The following command will scan all source files and create the Markdown output into `./API.md`:
```bash
npm run doc
```
## Authors

@@ -164,0 +192,0 @@

@@ -6,6 +6,4 @@ import { Promise } from 'es6-promise'

import formatText from './format_text'
import stringifyAsQueryParam from './stringify_as_query_param'
const fetch = fetchPonyfill(Promise)

@@ -15,2 +13,3 @@

/**
* @private
* imported from https://github.com/bigchaindb/js-utility-belt/

@@ -29,10 +28,10 @@ *

* `config.urlTemplateSpec`.
* @param {object} config Additional configuration, mostly passed to fetch as its 'init' config
* @param {Object} config Additional configuration, mostly passed to fetch as its 'init' config
* (see https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch#Parameters).
* @param {*} config.jsonBody Json payload to the request. Will automatically be
* JSON.stringify()-ed and override `config.body`.
* @param {string|object} config.query Query parameter to append to the end of the url.
* @param {string|Object} config.query Query parameter to append to the end of the url.
* If specified as an object, keys will be
* decamelized into snake case first.
* @param {*[]|object} config.urlTemplateSpec Format spec to use to expand the url (see sprintf).
* @param {*[]|Object} config.urlTemplateSpec Format spec to use to expand the url (see sprintf).
* @param {*} config.* All other options are passed through to fetch.

@@ -53,4 +52,4 @@ *

} else if (urlTemplateSpec &&
typeof urlTemplateSpec === 'object' &&
Object.keys(urlTemplateSpec).length) {
typeof urlTemplateSpec === 'object' &&
Object.keys(urlTemplateSpec).length) {
expandedUrl = formatText(url, urlTemplateSpec)

@@ -57,0 +56,0 @@ } else if (process.env.NODE_ENV !== 'production') {

import request from './request'
const HEADER_BLACKLIST = ['content-type']
/**
* Base connection
*/
export default class Connection {

@@ -41,3 +42,2 @@ constructor(path, headers = {}) {

/**
* @public
* @param blockHeight

@@ -54,3 +54,2 @@ */

/**
* @public
* @param transactionId

@@ -67,3 +66,2 @@ */

/**
* @public
* @param transactionId

@@ -81,3 +79,2 @@ * @param status

/**
* @public
* @param publicKey

@@ -101,3 +98,2 @@ * @param spent

/**
* @public
* @param assetId

@@ -116,3 +112,2 @@ * @param operation

/**
* @public
* @param blockId

@@ -129,3 +124,2 @@ */

/**
* @public
* @param transaction

@@ -141,3 +135,2 @@ */

/**
* @public
* @param transaction

@@ -153,3 +146,2 @@ */

/**
* @public
* @param transaction

@@ -159,3 +151,2 @@ */

return this._req(this.getApiUrls('transactionsCommit'), {
method: 'POST',

@@ -167,3 +158,2 @@ jsonBody: transaction

/**
* @public
* @param search

@@ -180,3 +170,2 @@ */

/**
* @public
* @param search

@@ -183,0 +172,0 @@ */

@@ -6,3 +6,3 @@ import base58 from 'bs58'

* @public
* @class Keypair Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* @type {Object}

@@ -9,0 +9,0 @@ * @param {Buffer} [seed] A seed that will be used as a key derivation function

@@ -14,3 +14,3 @@ import { sprintf } from 'sprintf-js'

* imported from https://github.com/bigchaindb/js-utility-belt/
*
* @private
* Formats strings similarly to C's sprintf, with the addition of '${...}' formats.

@@ -51,2 +51,3 @@ *

/**
* @private
* Interpolation algorithm inspired by sprintf-js.

@@ -74,3 +75,3 @@ *

while ((interpolationLeft = interpolationLeft.substring(curMatch[0].length)) &&
value != null) {
value != null) {
if ((curMatch = Regex.KEY_ACCESS.exec(interpolationLeft))) {

@@ -77,0 +78,0 @@ value = value[curMatch[1]]

import baseRequest from './baseRequest'
import sanitize from './sanitize'
const DEFAULT_REQUEST_CONFIG = {

@@ -12,2 +11,3 @@ headers: {

/**
* @private
* Small wrapper around js-utility-belt's request that provides url resolving,

@@ -14,0 +14,0 @@ * default settings, and response handling.

@@ -6,2 +6,3 @@ import coreIncludes from 'core-js/library/fn/array/includes'

/**
* @private
* Abstraction for selectFromObject and omitFromObject for DRYness.

@@ -25,2 +26,3 @@ * Set isInclusion to true if the filter should be for including the filtered items (ie. selecting

/**
* @private
* Returns a filtered copy of the given object's own enumerable properties (no inherited

@@ -45,8 +47,9 @@ * properties), keeping any keys that pass the given filter function.

/**
* @private
* Similar to lodash's _.pick(), this returns a copy of the given object's
* own and inherited enumerable properties, selecting only the keys in
* the given array or whose value pass the given filter function.
* @param {object} obj Source object
* @param {array|function} filter Array of key names to select or function to invoke per iteration
* @return {object} The new object
* @param {Object} obj Source object
* @param {Array|function} filter Array of key names to select or function to invoke per iteration
* @return {Object} The new object
*/

@@ -58,2 +61,3 @@ function selectFromObject(obj, filter) {

/**
* @private
* Glorified selectFromObject. Takes an object and returns a filtered shallow copy that strips out

@@ -63,4 +67,4 @@ * any properties that are falsy (including coercions, ie. undefined, null, '', 0, ...).

*
* @param {object} obj Javascript object
* @return {object} Sanitized Javascript object
* @param {Object} obj Javascript object
* @return {Object} Sanitized Javascript object
*/

@@ -67,0 +71,0 @@ export default function sanitize(obj) {

@@ -7,2 +7,3 @@ import coreObjectEntries from 'core-js/library/fn/object/entries'

/**
* @private
* imported from https://github.com/bigchaindb/js-utility-belt/

@@ -28,3 +29,3 @@ *

*
* @param {object} obj Query params dictionary
* @param {Object} obj Query params dictionary
* @param {function} [transform=decamelize] Transform function for each of the param keys

@@ -31,0 +32,0 @@ * @return {string} Query param string

@@ -9,7 +9,9 @@ import { Buffer } from 'buffer'

/**
* Construct Transactions
*/
export default class Transaction {
/**
* @public
* Canonically serializes a transaction into a string by sorting the keys
* @param {object} (transaction)
* @param {Object} (transaction)
* @return {string} a canonically serialized Transaction

@@ -58,8 +60,7 @@ */

/**
* @public
* Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
* the `issuers`.
* @param {object} asset Created asset's data
* @param {object} metadata Metadata for the Transaction
* @param {object[]} outputs Array of Output objects to add to the Transaction.
* @param {Object} asset Created asset's data
* @param {Object} metadata Metadata for the Transaction
* @param {Object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.

@@ -74,3 +75,3 @@ * For `CREATE` Transactions, this should usually just be a list of

* Transaction (`signTransaction()`).
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
* @returns {Object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!

@@ -88,3 +89,2 @@ */

/**
* @public
* Create an Ed25519 Cryptocondition from an Ed25519 public key

@@ -94,3 +94,3 @@ * to put into an Output of a Transaction

* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output)
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/

@@ -111,9 +111,8 @@ static makeEd25519Condition(publicKey, json = true) {

/**
* @public
* Create an Output from a Condition.
* Note: Assumes the given Condition was generated from a
* single public key (e.g. a Ed25519 Condition)
* @param {object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {Object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {string} amount Amount of the output
* @returns {object} An Output usable in a Transaction
* @returns {Object} An Output usable in a Transaction
*/

@@ -143,7 +142,6 @@ static makeOutput(condition, amount = '1') {

/**
* @public
* Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
* @param {string} preimage Preimage to be hashed and wrapped in a crypto-condition
* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
*/

@@ -161,3 +159,2 @@ static makeSha256Condition(preimage, json = true) {

/**
* @public
* Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction

@@ -167,3 +164,3 @@ * @param {number} threshold

* @param {boolean} [json=true] If true returns a json object otherwise a crypto-condition type
* @returns {object} Sha256 Threshold Condition (that will need to wrapped in an Output)
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
*/

@@ -187,9 +184,8 @@ static makeThresholdCondition(threshold, subconditions = [], json = true) {

/**
* @public
* Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
* the `fulfilledOutputs` of `unspentTransaction`.
* @param {object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
* @param {Object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
* its Output Condition)
* @param {object} metadata Metadata for the Transaction
* @param {object[]} outputs Array of Output objects to add to the Transaction.
* @param {Object} metadata Metadata for the Transaction
* @param {Object[]} outputs Array of Output objects to add to the Transaction.
* Think of these as the recipients of the asset after the transaction.

@@ -204,3 +200,3 @@ * For `TRANSFER` Transactions, this should usually just be a list of

* (`signTransaction()`).
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
* @returns {Object} Unsigned transaction -- make sure to call signTransaction() on it before
* sending it off!

@@ -234,3 +230,2 @@ */

/**
* @public
* Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`

@@ -240,7 +235,7 @@ * that's been signed.

* an exercise for the user.
* @param {object} transaction Transaction to sign. `transaction` is not modified.
* @param {Object} transaction Transaction to sign. `transaction` is not modified.
* @param {...string} privateKeys Private keys associated with the issuers of the `transaction`.
* Looped through to iteratively sign any Input Fulfillments found in
* the `transaction`.
* @returns {object} The signed version of `transaction`.
* @returns {Object} The signed version of `transaction`.
*/

@@ -267,3 +262,3 @@ static signTransaction(transaction, ...privateKeys) {

const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(signedTx)
Transaction.serializeTransactionIntoCanonicalString(signedTx)
signedTx.id = sha256Hash(serializedTransaction)

@@ -270,0 +265,0 @@ return signedTx

import base58 from 'bs58'
/**
* @public
* Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
* @param {cc.Fulfillment} fulfillment base58 encoded Ed25519 public key for recipient of the Transaction
* @returns {object} Ed25519 Condition (that will need to wrapped in an Output)
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/

@@ -9,0 +8,0 @@ export default function ccJsonify(fulfillment) {

@@ -6,5 +6,4 @@ import { Buffer } from 'buffer'

/**
* @public
* Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
* @param {object} conditionJson
* @param {Object} conditionJson
* @returns {cc.Condition} Ed25519 Condition (that will need to wrapped in an Output)

@@ -11,0 +10,0 @@ */

@@ -18,3 +18,17 @@ import test from 'ava'

test('Sha256Condition fulfillment', t => {
const preimage = 'secret'
const target = {
details: {
type_id: 0,
bitmask: 3,
preimage,
type: 'fulfillment'
},
uri: 'ni:///sha-256;K7gNU3sdo-OL0wNhqoVWhr3g6s1xYv72ol_pe_Unols?fpt=preimage-sha-256&cost=6'
}
t.deepEqual(target, Transaction.makeSha256Condition(preimage))
})
test('Threshold condition encoding', t => {

@@ -21,0 +35,0 @@ const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc