@iota/transaction
v1.0.0-beta.30
Published
IOTA transaction (de)serialization & guards.
Downloads
18,918
Readme
@iota/transaction
Utilities and validators for transactions.
Installation
Install using npm:
npm install @iota/transaction
or using yarn:
yarn add @iota/transaction
API Reference
static
inner
transaction.transactionHash(buffer, [offset])
Summary: Generates the transaction hash for a given transaction.
Throws:
- errors.ILLEGAL_TRANSACTION_BUFFER_LENGTH : Make sure that the
buffer
argument contains 8,019 trits (the length of a transaction without the transaction hash). - errors.ILLEGAL_TRANSACTION_OFFSET : Make sure that the
offset
argument is a multiple of 8,019 (the length of a transaction without the transaction hash).
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transactions in trits |
| [offset] | Number | 0 | Offset in trits to define a transaction to hash in the buffer
argument |
This method takes transaction trits, and returns the transaction hash.
Related methods
To validate the length of transaction trits, use the isMultipleOfTransactionLength()
method.
To get a transaction's trits from the Tangle, use the getTrytes()
method, then convert them to trits, using the trytesToTrits()
method.
Returns: Int8Array - Transaction hash
Example
let hash = Transaction.transactionHash(transactions);
transaction.isTransaction(transaction, [minWeightMagnitude])
Summary: Validates the structure and contents of a given transaction.
Throws:
- errors.ILLEGAL_MIN_WEIGHT_MAGNITUDE : Make sure that the
minWeightMagnitude
argument is a number between 1 and 81. - errors.ILLEGAL_TRANSACTION_BUFFER_LENGTH : Make sure that the
transaction
argument contains 8,019 trits (the length of a transaction without the transaction hash).
| Param | Type | Default | Description | | --- | --- | --- | --- | | transaction | Int8Array | | Transaction trits | | [minWeightMagnitude] | number | 0 | Minimum weight magnitude |
This method takes an array of transaction trits and validates whether they form a valid transaction by checking the following:
- Addresses in value transactions have a 0 trit at the end, which means they were generated using the Kerl hashing function
- The transaction would result in a valid hash, according to the given
minWeightMagnitude
argument
Related methods
To get a transaction's trits from the Tangle, use the getTrytes()
method, then convert them to trits, using the trytesToTrits()
method.
Returns: boolean - valid - Whether the transaction is valid.
Example
let valid = Transaction.isTransaction(transaction);
transaction.isTailTransaction(transaction)
Summary: Checks if the given transaction is a tail transaction in a bundle.
Throws:
- errors.ILLEGAL_TRANSACTION_BUFFER_LENGTH : Make sure that the
transaction
argument contains 8,019 trits (the length of a transaction without the transaction hash).
| Param | Type | Description | | --- | --- | --- | | transaction | Int8Array | Transaction trits |
This method takes an array of transaction trits, and checks its currentIndex
field to validate whether it is the tail transaction in a bundle.
Related methods
To get a transaction's trits from the Tangle, use the getTrytes()
method, then convert them to trits, using the trytesToTrits()
method.
Returns: boolean - tail - Whether the transaction is a tail transaction.
Example
let tail = Transaction.isTailTransaction(transaction);
transaction.isHeadTransaction(transaction)
Summary: Checks if the given transaction is a head transaction in a bundle.
Throws:
- errors.ILLEGAL_TRANSACTION_BUFFER_LENGTH : Make sure that the
transaction
argument contains 8,019 trits (the length of a transaction without the transaction hash).
| Param | Type | Description | | --- | --- | --- | | transaction | Int8Array | Transaction trits |
This method takes an array of transaction trits, and checks its currentIndex
field to validate whether it is the head transaction in a bundle.
Related methods
To get a transaction's trits from the Tangle, use the getTrytes()
method, then convert them to trits, using the trytesToTrits()
method.
Returns: boolean - head - Whether the transaction is a head transaction.
Example
let head = Transaction.isHeadTransaction(transaction);
transaction~isMultipleOfTransactionLength(lengthOrOffset)
| Param | Type | | --- | --- | | lengthOrOffset | Int8Array |
Checks if given value is a valid transaction buffer length or offset.
transaction~signatureOrMessage(buffer)
| Param | Type | Description | | --- | --- | --- | | buffer | Int8Array | Transaction trytes |
Gets the signatureOrMessage
field of all transactions in a bundle.
transaction~address(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of address
field.
transaction~value(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of value
field.
transaction~obsoleteTag(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of obsoleteTag
field.
transaction~issuanceTimestamp(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of issuanceTimestamp
field.
transaction~currentIndex(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of currentIndex
field.
transaction~lastIndex(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of lastIndex
field.
transaction~bundle(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of bundle
field.
transaction~trunkTransaction(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of trunkTransaction
field.
transaction~branchTransaction(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of branchTransaction
field.
transaction~tag(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of tag
field.
transaction~attachmentTimestamp(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of attachmentTimestamp
field.
transaction~attachmentTimestampLowerBound(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of attachmentTimestampLowerBound
field.
transaction~attachmentTimestampUpperBound(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of attachmentTimestampUpperBound
field.
transaction~transactionNonce(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of tansactionNonce
field.
transaction~bundle(buffer, [offset])
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. | | [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of transaction essence fields.