npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iota/transaction

v1.0.0-beta.30

Published

IOTA transaction (de)serialization & guards.

Downloads

11,589

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

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.