1.0.0-beta.30 • Published 4 years ago

@iota/transaction v1.0.0-beta.30

Weekly downloads
2,333
License
MIT
Repository
github
Last release
4 years ago

@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
offsetNumber0Offset 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).
ParamTypeDefaultDescription
transactionInt8ArrayTransaction trits
minWeightMagnitudenumber0Minimum 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).
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.

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

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)

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
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction 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.
offsetNumber0Transaction trit offset. It must be a multiple of transaction length.

Returns a copy of transaction essence fields.