Socket
Socket
Sign inDemoInstall

@iota/transaction

Package Overview
Dependencies
6
Maintainers
6
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @iota/transaction

IOTA transaction (de)serialization & guards.


Version published
Weekly downloads
1.5K
decreased by-11.78%
Maintainers
6
Install size
2.47 MB
Created
Weekly downloads
 

Readme

Source

@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).
ParamTypeDefaultDescription
bufferInt8ArrayTransactions in trits
[offset]Number0Offset in trits to define a transaction to hash in the buffer argument

This method takes transaction trits, and returns the transaction hash.

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).
ParamTypeDefaultDescription
transactionInt8ArrayTransaction trits
[minWeightMagnitude]number0Minimum 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

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).
ParamTypeDescription
transactionInt8ArrayTransaction 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.

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).
ParamTypeDescription
transactionInt8ArrayTransaction 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.

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)

ParamType
lengthOrOffsetInt8Array

Checks if given value is a valid transaction buffer length or offset.

transaction~signatureOrMessage(buffer)

ParamTypeDescription
bufferInt8ArrayTransaction trytes

Gets the signatureOrMessage field of all transactions in a bundle.

transaction~address(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of address field.

transaction~value(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of value field.

transaction~obsoleteTag(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of obsoleteTag field.

transaction~issuanceTimestamp(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of issuanceTimestamp field.

transaction~currentIndex(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of currentIndex field.

transaction~lastIndex(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of lastIndex field.

transaction~bundle(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of bundle field.

transaction~trunkTransaction(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of trunkTransaction field.

transaction~branchTransaction(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of branchTransaction field.

transaction~tag(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of tag field.

transaction~attachmentTimestamp(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of attachmentTimestamp field.

transaction~attachmentTimestampLowerBound(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of attachmentTimestampLowerBound field.

transaction~attachmentTimestampUpperBound(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of attachmentTimestampUpperBound field.

transaction~transactionNonce(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of tansactionNonce field.

transaction~bundle(buffer, [offset])

ParamTypeDefaultDescription
bufferInt8ArrayTransaction buffer. Buffer length must be a multiple of transaction length.
[offset]Number0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of transaction essence fields.

Keywords

FAQs

Last updated on 18 Jun 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc