1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +01:00
js-bigchaindb-driver/API.md

517 lines
15 KiB
Markdown
Raw Normal View History

<!---
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
--->
2017-05-03 01:02:50 +02:00
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [Ed25519Keypair][1]
2018-07-05 13:53:15 +02:00
- [Parameters][2]
- [Properties][3]
- [Connection][4]
- [Parameters][5]
- [getBlock][6]
- [Parameters][7]
- [getTransaction][8]
- [Parameters][9]
- [listBlocks][10]
- [Parameters][11]
- [listOutputs][12]
- [Parameters][13]
- [listTransactions][14]
- [Parameters][15]
- [listVotes][16]
- [Parameters][17]
- [postTransaction][18]
- [Parameters][19]
- [postTransactionSync][20]
- [Parameters][21]
- [postTransactionAsync][22]
- [Parameters][23]
- [postTransactionCommit][24]
- [Parameters][25]
- [searchAssets][26]
- [Parameters][27]
- [searchMetadata][28]
- [Parameters][29]
- [Transaction][30]
- [serializeTransactionIntoCanonicalString][31]
- [Parameters][32]
- [makeCreateTransaction][33]
- [Parameters][34]
- [makeEd25519Condition][35]
- [Parameters][36]
- [makeOutput][37]
- [Parameters][38]
- [makeSha256Condition][39]
- [Parameters][40]
- [makeThresholdCondition][41]
- [Parameters][42]
- [makeTransferTransaction][43]
- [Parameters][44]
- [signTransaction][45]
- [Parameters][46]
- [ccJsonLoad][47]
- [Parameters][48]
- [ccJsonify][49]
- [Parameters][50]
2017-05-03 01:02:50 +02:00
## Ed25519Keypair
2018-07-05 13:53:15 +02:00
[src/Ed25519Keypair.js:12-17][51]
2018-07-05 13:53:15 +02:00
Type: [Object][52]
2018-07-05 13:53:15 +02:00
### Parameters
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
- `seed` **[Buffer][53]?** A seed that will be used as a key derivation function
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
### Properties
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
- `publicKey` **[string][54]**
- `privateKey` **[string][54]**
## Connection
2018-07-05 13:53:15 +02:00
[src/connection.js:8-178][55]
Base connection
2018-07-05 13:53:15 +02:00
### Parameters
- `path`
- `headers` (optional, default `{}`)
### getBlock
2018-07-05 13:53:15 +02:00
[src/connection.js:45-51][56]
2018-07-05 13:53:15 +02:00
#### Parameters
- `blockHeight`
### getTransaction
2018-07-05 13:53:15 +02:00
[src/connection.js:56-62][57]
2018-07-05 13:53:15 +02:00
#### Parameters
- `transactionId`
2017-05-03 01:02:50 +02:00
### listBlocks
2018-07-05 13:53:15 +02:00
[src/connection.js:68-74][58]
2018-07-05 13:53:15 +02:00
#### Parameters
- `transactionId`
- `status`
### listOutputs
2018-07-05 13:53:15 +02:00
[src/connection.js:80-92][59]
2018-07-05 13:53:15 +02:00
#### Parameters
- `publicKey`
- `spent`
### listTransactions
2018-07-05 13:53:15 +02:00
[src/connection.js:98-105][60]
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
2017-05-03 01:02:50 +02:00
- `assetId`
- `operation`
2017-05-03 01:02:50 +02:00
### listVotes
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[src/connection.js:110-116][61]
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
2017-05-03 01:02:50 +02:00
- `blockId`
2017-05-03 01:02:50 +02:00
### postTransaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[src/connection.js:121-123][62]
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
2017-05-03 01:02:50 +02:00
- `transaction`
2017-05-03 01:02:50 +02:00
### postTransactionSync
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[src/connection.js:128-133][63]
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
- `transaction`
### postTransactionAsync
[src/connection.js:139-144][64]
#### Parameters
2017-05-03 01:02:50 +02:00
- `transaction`
### postTransactionCommit
2018-07-05 13:53:15 +02:00
[src/connection.js:150-155][65]
2018-07-05 13:53:15 +02:00
#### Parameters
- `transaction`
### searchAssets
2018-07-05 13:53:15 +02:00
[src/connection.js:160-166][66]
2018-07-05 13:53:15 +02:00
#### Parameters
- `search`
### searchMetadata
2018-07-05 13:53:15 +02:00
[src/connection.js:171-177][67]
2018-07-05 13:53:15 +02:00
#### Parameters
- `search`
## Transaction
2018-07-05 13:53:15 +02:00
[src/transaction.js:12-254][68]
Construct Transactions
### serializeTransactionIntoCanonicalString
2018-07-05 13:53:15 +02:00
[src/transaction.js:18-25][69]
Canonically serializes a transaction into a string by sorting the keys
2018-07-05 13:53:15 +02:00
#### Parameters
- `transaction`
2018-07-05 13:53:15 +02:00
- `null` **[Object][52]** (transaction)
2018-07-05 13:53:15 +02:00
Returns **[string][54]** a canonically serialized Transaction
### makeCreateTransaction
2018-07-05 13:53:15 +02:00
[src/transaction.js:76-83][70]
Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
the `issuers`.
2018-07-05 13:53:15 +02:00
#### Parameters
2018-07-05 13:53:15 +02:00
- `asset` **[Object][52]** Created asset's data
- `metadata` **[Object][52]** Metadata for the Transaction
- `outputs` **[Array][71]&lt;[Object][52]>** Array of Output objects to add to the Transaction.
2017-05-03 01:02:50 +02:00
Think of these as the recipients of the asset after the transaction.
For `CREATE` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the issuers' public
keys (so that the issuers are the recipients of the created asset).
2018-07-05 13:53:15 +02:00
- `issuers` **...[Array][71]&lt;[string][54]>** Public key of one or more issuers to the asset being created by this
2017-05-03 01:02:50 +02:00
Transaction.
Note: Each of the private keys corresponding to the given public
keys MUST be used later (and in the same order) when signing the
Transaction (`signTransaction()`).
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** Unsigned transaction -- make sure to call signTransaction() on it before
2017-05-03 01:02:50 +02:00
sending it off!
### makeEd25519Condition
2018-07-05 13:53:15 +02:00
[src/transaction.js:92-103][72]
Create an Ed25519 Cryptocondition from an Ed25519 public key
to put into an Output of a Transaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
- `publicKey` **[string][54]** 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`)
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Output)
### makeOutput
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[src/transaction.js:113-133][74]
2017-05-03 01:02:50 +02:00
Create an Output from a Condition.
Note: Assumes the given Condition was generated from a
single public key (e.g. a Ed25519 Condition)
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
- `condition` **[Object][52]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
- `amount` **[string][54]** Amount of the output (optional, default `'1'`)
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** An Output usable in a Transaction
### makeSha256Condition
2018-07-05 13:53:15 +02:00
[src/transaction.js:141-149][75]
Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
2018-07-05 13:53:15 +02:00
#### Parameters
2018-07-05 13:53:15 +02:00
- `preimage` **[string][54]** 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`)
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** Preimage-Sha256 Condition (that will need to wrapped in an Output)
### makeThresholdCondition
2018-07-05 13:53:15 +02:00
[src/transaction.js:158-172][76]
Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
2018-07-05 13:53:15 +02:00
#### Parameters
2018-07-05 13:53:15 +02:00
- `threshold` **[number][77]**
- `subconditions` **[Array][71]** (optional, default `[]`)
- `json` **[boolean][73]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** Sha256 Threshold Condition (that will need to wrapped in an Output)
### makeTransferTransaction
2018-07-05 13:53:15 +02:00
[src/transaction.js:195-216][78]
Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
the `fulfilledOutputs` of `unspentTransaction`.
2018-07-05 13:53:15 +02:00
#### Parameters
- `unspentOutputs`
2018-07-05 13:53:15 +02:00
- `outputs` **[Array][71]&lt;[Object][52]>** Array of Output objects to add to the Transaction.
2017-05-03 01:02:50 +02:00
Think of these as the recipients of the asset after the transaction.
For `TRANSFER` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the public keys of
the recipients.
2018-07-05 13:53:15 +02:00
- `metadata` **[Object][52]** Metadata for the Transaction
- `unspentTransaction` **[Object][52]** Previous Transaction you have control over (i.e. can fulfill
its Output Condition)
2018-07-05 13:53:15 +02:00
- `OutputIndices` **...[number][77]** Indices of the Outputs in `unspentTransaction` that this
2017-05-03 01:02:50 +02:00
Transaction fulfills.
Note that listed public keys listed must be used (and in
the same order) to sign the Transaction
2017-05-03 01:02:50 +02:00
(`signTransaction()`).
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** Unsigned transaction -- make sure to call signTransaction() on it before
2017-05-03 01:02:50 +02:00
sending it off!
### signTransaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[src/transaction.js:229-253][79]
2017-05-03 01:02:50 +02:00
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.
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
#### Parameters
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
- `transaction` **[Object][52]** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string][54]** Private keys associated with the issuers of the `transaction`.
2017-05-03 01:02:50 +02:00
Looped through to iteratively sign any Input Fulfillments found in
the `transaction`.
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** The signed version of `transaction`.
2017-05-03 01:02:50 +02:00
## ccJsonLoad
2018-07-05 13:53:15 +02:00
[src/utils/ccJsonLoad.js:10-40][80]
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
2018-07-05 13:53:15 +02:00
### Parameters
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
- `conditionJson` **[Object][52]**
2017-05-03 01:02:50 +02:00
Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)
## ccJsonify
2018-07-05 13:53:15 +02:00
[src/utils/ccJsonify.js:8-61][81]
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
2018-07-05 13:53:15 +02:00
### Parameters
2017-05-03 01:02:50 +02:00
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Output)
2017-05-03 01:02:50 +02:00
[1]: #ed25519keypair
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[2]: #parameters
[3]: #properties
[4]: #connection
[5]: #parameters-1
[6]: #getblock
[7]: #parameters-2
[8]: #gettransaction
[9]: #parameters-3
[10]: #listblocks
[11]: #parameters-4
[12]: #listoutputs
[13]: #parameters-5
[14]: #listtransactions
[15]: #parameters-6
[16]: #listvotes
[17]: #parameters-7
[18]: #posttransaction
[19]: #parameters-8
[20]: #posttransactionsync
[21]: #parameters-9
[22]: #posttransactionasync
[23]: #parameters-10
[24]: #posttransactioncommit
[25]: #parameters-11
[26]: #searchassets
[27]: #parameters-12
[28]: #searchmetadata
[29]: #parameters-13
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[30]: #transaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[31]: #serializetransactionintocanonicalstring
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[32]: #parameters-14
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[33]: #makecreatetransaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[34]: #parameters-15
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[35]: #makeed25519condition
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[36]: #parameters-16
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[37]: #makeoutput
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[38]: #parameters-17
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[39]: #makesha256condition
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[40]: #parameters-18
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[41]: #makethresholdcondition
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[42]: #parameters-19
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[43]: #maketransfertransaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[44]: #parameters-20
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[45]: #signtransaction
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[46]: #parameters-21
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[47]: #ccjsonload
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[48]: #parameters-22
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[49]: #ccjsonify
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[50]: #parameters-23
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[51]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/Ed25519Keypair.js#L12-L17 "Source code on GitHub"
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[52]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[53]: https://nodejs.org/api/buffer.html
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
2017-05-03 01:02:50 +02:00
2018-07-05 13:53:15 +02:00
[55]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L8-L178 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[56]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L45-L51 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[57]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L56-L62 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[58]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L68-L74 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[59]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L80-L92 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[60]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L98-L105 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[61]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L110-L116 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[62]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L121-L123 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[63]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L128-L133 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[64]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L139-L144 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[65]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L150-L155 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[66]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L160-L166 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[67]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/connection.js#L171-L177 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[68]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L12-L254 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[69]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L18-L25 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[70]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L76-L83 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[71]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
2018-07-05 13:53:15 +02:00
[72]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L92-L103 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[73]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
2018-07-05 13:53:15 +02:00
[74]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L113-L133 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[75]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L141-L149 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[76]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L158-L172 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[77]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
2018-07-05 13:53:15 +02:00
[78]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L195-L216 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[79]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/transaction.js#L229-L253 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[80]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/utils/ccJsonLoad.js#L10-L40 "Source code on GitHub"
2018-07-05 13:53:15 +02:00
[81]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/6a637f33e21a9f43503ec51f923bfdad60c57458/src/utils/ccJsonify.js#L8-L61 "Source code on GitHub"