Skip to main content

Class: Utils

Utils class for utils.

Table of contents​

Constructors​

Methods​

Constructors​

constructor​

• new Utils()

Methods​

generateMnemonic​

▸ Static generateMnemonic(): string

Generate a new mnemonic.

Returns​

string


mnemonicToHexSeed​

▸ Static mnemonicToHexSeed(mnemonic): string

Convert a mnemonic to a hex encoded seed.

Parameters​

NameTypeDescription
mnemonicstringA mnemonic string.

Returns​

string

The seed as hex-encoded string.


computeAliasId​

▸ Static computeAliasId(outputId): string

Compute the alias ID from a given Alias output ID.

Parameters​

NameTypeDescription
outputIdstringThe output ID as hex-encoded string.

Returns​

string

The Alias ID.


computeFoundryId​

▸ Static computeFoundryId(aliasId, serialNumber, tokenSchemeType): string

Compute the Foundry ID.

Parameters​

NameTypeDescription
aliasIdstringThe Alias ID associated with the Foundry.
serialNumbernumberThe serial number of the Foundry.
tokenSchemeTypenumberThe Token scheme type. Currently only a simple scheme is supported.

Returns​

string

The Foundry ID.


computeNftId​

▸ Static computeNftId(outputId): string

Compute the NFT ID from the given NFT output ID.

Parameters​

NameTypeDescription
outputIdstringThe output ID as hex-encoded string.

Returns​

string

The NFT ID.


computeInputsCommitment​

▸ Static computeInputsCommitment(inputs): string

Compute the input commitment from the output objects that are used as inputs to fund the transaction.

Parameters​

NameTypeDescription
inputsOutput[]The output objects used as inputs for the transaction.

Returns​

string

The inputs commitment hash as hex-encoded string.


computeOutputId​

▸ Static computeOutputId(id, index): string

Compute the output ID from transaction ID and output index.

Parameters​

NameType
idstring
indexnumber

Returns​

string

The output ID.


computeStorageDeposit​

▸ Static computeStorageDeposit(output, rent): bigint

Compute the required storage deposit of an output.

Parameters​

NameTypeDescription
outputOutputThe output.
rentIRentRent cost of objects which take node resources.

Returns​

bigint

The required storage deposit.


computeTokenId​

▸ Static computeTokenId(aliasId, serialNumber, tokenSchemeType): string

Compute a Token iD from the aliasId, serial number and token scheme type.

Parameters​

NameTypeDescription
aliasIdstringThe alias that controls the foundry.
serialNumbernumberThe serial number of the foundry.
tokenSchemeTypeSimpleThe tokenSchemeType of the foundry.

Returns​

string

The tokenId.


parseBech32Address​

▸ Static parseBech32Address(address): Address

Parse a Bech32 address from a string.

Parameters​

NameTypeDescription
addressstringA Bech32 address as string.

Returns​

Address

A Bech32 address.


blockId​

▸ Static blockId(block): string

Compute the block ID (Blake2b256 hash of the block bytes) of a block.

Parameters​

NameTypeDescription
blockBlockA block.

Returns​

string

The corresponding block ID.


milestoneId​

▸ Static milestoneId(payload): string

Compute the milestone ID (Blake2b256 hash of the milestone essence) of a milestone payload.

Parameters​

NameTypeDescription
payloadMilestonePayloadA milestone payload.

Returns​

string

The milestone ID.


transactionId​

▸ Static transactionId(payload): string

Compute the transaction ID (Blake2b256 hash of the provided transaction payload) of a transaction payload.

Parameters​

NameTypeDescription
payloadTransactionPayloadA transaction payload.

Returns​

string

The transaction ID.


bech32ToHex​

▸ Static bech32ToHex(bech32): string

Convert a Bech32 address to a hex-encoded string.

Parameters​

NameTypeDescription
bech32stringA Bech32 address.

Returns​

string

The hex-encoded string.


hexToBech32​

▸ Static hexToBech32(hex, bech32Hrp): string

Convert a hex-encoded address string to a Bech32-encoded address string.

Parameters​

NameTypeDescription
hexstringA hex-encoded address string.
bech32HrpstringThe Bech32 HRP (human readable part) to use.

Returns​

string

The Bech32-encoded address string.


aliasIdToBech32​

▸ Static aliasIdToBech32(aliasId, bech32Hrp): string

Convert an Alias ID to a Bech32-encoded address string.

Parameters​

NameTypeDescription
aliasIdstringAn Alias ID.
bech32HrpstringThe Bech32 HRP (human readable part) to use.

Returns​

string

The Bech32-encoded address string.


nftIdToBech32​

▸ Static nftIdToBech32(nftId, bech32Hrp): string

Convert an NFT ID to a Bech32-encoded address string.

Parameters​

NameTypeDescription
nftIdstringAn NFT ID.
bech32HrpstringThe Bech32 HRP (human readable part) to use.

Returns​

string

The Bech32-encoded address string.


hexPublicKeyToBech32Address​

▸ Static hexPublicKeyToBech32Address(hex, bech32Hrp): string

Convert a hex-encoded public key to a Bech32-encoded address string.

Parameters​

NameTypeDescription
hexstringA hex-encoded public key.
bech32HrpstringThe Bech32 HRP (human readable part) to use.

Returns​

string

The Bech32-encoded address string.


isAddressValid​

▸ Static isAddressValid(address): boolean

Checks whether an address string is a valid Bech32-encoded address.

Parameters​

NameTypeDescription
addressstringAn address string.

Returns​

boolean


hashTransactionEssence​

▸ Static hashTransactionEssence(essence): string

Compute the hash of a transaction essence.

Parameters​

NameTypeDescription
essenceTransactionEssenceA transaction essence.

Returns​

string

The hash of the transaction essence as a hex-encoded string.


verifyEd25519Signature​

▸ Static verifyEd25519Signature(signature, message): boolean

Verify an Ed25519 signature against a message.

Parameters​

NameTypeDescription
signatureEd25519SignatureAn Ed25519 signature.
messagestringA hex-encoded message.

Returns​

boolean


verifySecp256k1EcdsaSignature​

▸ Static verifySecp256k1EcdsaSignature(publicKey, signature, message): boolean

Verify a Secp256k1Ecdsa signature against a message.

Parameters​

NameTypeDescription
publicKeystringA hex-encoded public key.
signaturestringA hex-encoded signature.
messagestringA hex-encoded message.

Returns​

boolean


verifyMnemonic​

▸ Static verifyMnemonic(mnemonic): void

Verify if a mnemonic is a valid BIP39 mnemonic.

Parameters​

NameTypeDescription
mnemonicstringA mnemonic string.

Returns​

void