1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-06-29 00:57:44 +02:00
js-bigchaindb-driver/API.md

423 lines
13 KiB
Markdown
Raw Normal View History

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]
- [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]
2017-05-03 01:02:50 +02:00
## Ed25519Keypair
[src/Ed25519Keypair.js:12-17][25]
Type: [Object][26]
2017-05-03 01:02:50 +02:00
**Parameters**
- `seed` **[Buffer][27]?** A seed that will be used as a key derivation function
2017-05-03 01:02:50 +02:00
**Properties**
- `publicKey` **[string][28]**
- `privateKey` **[string][28]**
## Connection
[src/connection.js:8-168][29]
Base connection
**Parameters**
- `path`
- `headers` (optional, default `{}`)
### getBlock
[src/connection.js:44-50][30]
**Parameters**
- `blockHeight`
### getTransaction
[src/connection.js:55-61][31]
**Parameters**
- `transactionId`
2017-05-03 01:02:50 +02:00
### listBlocks
[src/connection.js:67-73][32]
**Parameters**
- `transactionId`
- `status`
### listOutputs
[src/connection.js:79-91][33]
**Parameters**
- `publicKey`
- `spent`
### listTransactions
[src/connection.js:97-104][34]
2017-05-03 01:02:50 +02:00
**Parameters**
- `assetId`
- `operation`
2017-05-03 01:02:50 +02:00
### listVotes
2017-05-03 01:02:50 +02:00
[src/connection.js:109-115][35]
2017-05-03 01:02:50 +02:00
**Parameters**
- `blockId`
2017-05-03 01:02:50 +02:00
### postTransaction
2017-05-03 01:02:50 +02:00
[src/connection.js:120-125][36]
2017-05-03 01:02:50 +02:00
**Parameters**
- `transaction`
2017-05-03 01:02:50 +02:00
### postTransactionSync
2017-05-03 01:02:50 +02:00
[src/connection.js:130-135][37]
2017-05-03 01:02:50 +02:00
**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.
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).
- `issuers` **...[Array][44]&lt;[string][28]>** 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()`).
Returns **[Object][26]** Unsigned transaction -- make sure to call signTransaction() on it before
2017-05-03 01:02:50 +02:00
sending it off!
### makeEd25519Condition
[src/transaction.js:92-103][45]
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
**Parameters**
- `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][26]** Ed25519 Condition (that will need to wrapped in an Output)
### makeOutput
2017-05-03 01:02:50 +02:00
[src/transaction.js:113-133][47]
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
**Parameters**
- `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.
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.
- `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
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()`).
Returns **[Object][26]** 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
[src/transaction.js:229-252][52]
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
**Parameters**
- `transaction` **[Object][26]** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string][28]** 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`.
Returns **[Object][26]** The signed version of `transaction`.
2017-05-03 01:02:50 +02:00
## ccJsonLoad
[src/utils/ccJsonLoad.js:10-40][53]
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
2017-05-03 01:02:50 +02:00
**Parameters**
- `conditionJson` **[Object][26]**
2017-05-03 01:02:50 +02:00
Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)
## ccJsonify
[src/utils/ccJsonify.js:8-61][54]
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
2017-05-03 01:02:50 +02:00
**Parameters**
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
2017-05-03 01:02:50 +02:00
Returns **[Object][26]** 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
[2]: #connection
2017-05-03 01:02:50 +02:00
[3]: #getblock
2017-05-03 01:02:50 +02:00
[4]: #gettransaction
2017-05-03 01:02:50 +02:00
[5]: #listblocks
2017-05-03 01:02:50 +02:00
[6]: #listoutputs
2017-05-03 01:02:50 +02:00
[7]: #listtransactions
2017-05-03 01:02:50 +02:00
[8]: #listvotes
2017-05-03 01:02:50 +02:00
[9]: #posttransaction
2017-05-03 01:02:50 +02:00
[10]: #posttransactionsync
2017-05-03 01:02:50 +02:00
[11]: #posttransactioncommit
2017-05-03 01:02:50 +02:00
[12]: #searchassets
2017-05-03 01:02:50 +02:00
[13]: #searchmetadata
2017-05-03 01:02:50 +02:00
[14]: #transaction
2017-05-03 01:02:50 +02:00
[15]: #serializetransactionintocanonicalstring
2017-05-03 01:02:50 +02:00
[16]: #makecreatetransaction
2017-05-03 01:02:50 +02:00
[17]: #makeed25519condition
2017-05-03 01:02:50 +02:00
[18]: #makeoutput
2017-05-03 01:02:50 +02:00
[19]: #makesha256condition
2017-05-03 01:02:50 +02:00
[20]: #makethresholdcondition
2017-05-03 01:02:50 +02:00
[21]: #maketransfertransaction
2017-05-03 01:02:50 +02:00
[22]: #signtransaction
2017-05-03 01:02:50 +02:00
[23]: #ccjsonload
2017-05-03 01:02:50 +02:00
[24]: #ccjsonify
2017-05-03 01:02:50 +02:00
[25]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/691fadfd9887d59fcff4877d9f90521da11ef950/src/Ed25519Keypair.js#L12-L17 "Source code on GitHub"
2017-05-03 01:02:50 +02:00
[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
2017-05-03 01:02:50 +02:00
[27]: https://nodejs.org/api/buffer.html
2017-05-03 01:02:50 +02:00
[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"