Utilities for generating and signing bundles
Utilities for generating and signing bundles.
A bundle in IOTA is an atomic set of transactions.
Install using npm:
```
npm install @iota/bundle
or using yarn:
``
yarn add @iota/bundle
* bundle
* _static_
* .addEntry(entry, bundle)
* .addSignatureOrMessage(bundle, signatureOrMessage, index)
* _inner_
* [~createBundle([entries])](#module_bundle..createBundle)
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the bundle argument contains valid transaction tritsentry.signatureOrMessage
- errors.ILLEGAL\_SIGNATURE\_OR\_MESSAGE\_LENGTH : Make sure that the argument contains 6,561 tritsentry.address
- errors.ILLEGAL\_ADDRESS\_LENGTH : Make sure that the argument contains 243 tritsentry.value
- errors.ILLEGAL\_VALUE\_LENGTH : Make sure that the argument contains 6,561 tritsentry.timestamp
- errors.ILLEGAL\_ISSUANCE\_TIMESTAMP\_LENGTH : Make sure that the argument contains 81 trits
| Param | Type | Description |
| --- | --- | --- |
| entry | object | Transaction entry object |
| entry.address | Int8Array | An address in trits |
| entry.value | Int8Array | An amount of IOTA tokens in trits |
| [entry.signatureOrMessage] | Int8Array | Signature fragments or a message in trits |
| [entry.issuanceTimestamp] | Int8Array | Unix epoch in trits |
| [entry.tag] | Int8Array | (deprecated) |
| bundle | Int8Array | Bundle array to which to add the entry object |
Adds transaction trits in the given entry object to a given bundle array.
See the converter package for methods that convert values to trits.
Returns: Int8Array - A copy of the original bundle that also includes the added entries.
Example
`js
let bundle = new Int8Array();
bundle = Bundle.addEntry(bundle, {
address: Converter.trytesToTrits(outputAddress),
value: Converter.valueToTrits(value),
issuanceTimestamp: Converter.valueToTrits(Math.floor(Date.now() / 1000));
});
`
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the bundle argument contains valid transaction trits
| Param | Type | Description |
| --- | --- | --- |
| bundle | Int8Array | Transaction trits |
This method takes an array of transaction trits, generates the bundle hash, and adds it to each transaction.
See the addEntry() method for creating new bundles.
Returns: Int8Array - Transaction trits that include a bundle hash
Example
`js`
const result = Bundle.finalizeBundle(bundle);
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the bundle argument contains valid transaction tritsindex
- errors.ILLEGAL\_TRANSACTION\_INDEX : Make sure that the argument is a number and that the bundle contains enough transactionssignatureOrMessage
- errors.ILLEGAL\_SIGNATURE\_OR\_MESSAGE\_LENGTH : Make sure that the argument contains at least 6,561 trits
| Param | Type | Description |
| --- | --- | --- |
| bundle | Int8Array | Transaction trits |
| signatureOrMessage | Int8Array | Signature or message to add to the bundle |
| index | number | Transaction index at which to start adding the signature or message |
This method takes an array of transaction trits, and add the given message or signature to the transactions, starting from the given index.
If the signature or message is too long to fit in a single transaction, it is split across the next transaction in the bundle, starting from the given index.
See the addEntry() method for creating new bundles.
Returns: Int8Array - Transaction trits that include a bundle hash.
Example
`js``
const signature = Converter.trytesToTrits('SIGNATURE...')
bundle.set(Bundle.addSignatureOrMessage(bundle, signature, 1));
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [entries] | Array.<BundleEntry> | [] | Entries of single or multiple transactions with the same address |
Returns: Array.<Int8Array> - List of transactions in the bundle