Class: Utils
Utils class for utils.
Table of contents
Constructors
Methods
- generateMnemonic
- mnemonicToHexSeed
- computeAliasId
- computeFoundryId
- computeNftId
- computeInputsCommitment
- computeOutputId
- computeStorageDeposit
- computeTokenId
- parseBech32Address
- blockId
- milestoneId
- transactionId
- bech32ToHex
- hexToBech32
- aliasIdToBech32
- nftIdToBech32
- hexPublicKeyToBech32Address
- isAddressValid
- hashTransactionEssence
- verifyEd25519Signature
- verifySecp256k1EcdsaSignature
- verifyMnemonic
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
Name | Type | Description |
---|---|---|
mnemonic | string | A 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
Name | Type | Description |
---|---|---|
outputId | string | The output ID as hex-encoded string. |
Returns
string
The Alias ID.
computeFoundryId
▸ Static
computeFoundryId(aliasId
, serialNumber
, tokenSchemeType
): string
Compute the Foundry ID.
Parameters
Name | Type | Description |
---|---|---|
aliasId | string | The Alias ID associated with the Foundry. |
serialNumber | number | The serial number of the Foundry. |
tokenSchemeType | number | The 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
Name | Type | Description |
---|---|---|
outputId | string | The 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
Name | Type | Description |
---|---|---|
inputs | Output [] | 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
Name | Type |
---|---|
id | string |
index | number |
Returns
string
The output ID.
computeStorageDeposit
▸ Static
computeStorageDeposit(output
, rent
): bigint
Compute the required storage deposit of an output.
Parameters
Name | Type | Description |
---|---|---|
output | Output | The output. |
rent | IRent | Rent 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
Name | Type | Description |
---|---|---|
aliasId | string | The alias that controls the foundry. |
serialNumber | number | The serial number of the foundry. |
tokenSchemeType | Simple | The tokenSchemeType of the foundry. |
Returns
string
The tokenId.
parseBech32Address
▸ Static
parseBech32Address(address
): Address
Parse a Bech32 address from a string.
Parameters
Name | Type | Description |
---|---|---|
address | string | A Bech32 address as string. |
Returns
A Bech32 address.
blockId
▸ Static
blockId(block
): string
Compute the block ID (Blake2b256 hash of the block bytes) of a block.
Parameters
Name | Type | Description |
---|---|---|
block | Block | A 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
Name | Type | Description |
---|---|---|
payload | MilestonePayload | A 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
Name | Type | Description |
---|---|---|
payload | TransactionPayload | A transaction payload. |
Returns
string
The transaction ID.
bech32ToHex
▸ Static
bech32ToHex(bech32
): string
Convert a Bech32 address to a hex-encoded string.
Parameters
Name | Type | Description |
---|---|---|
bech32 | string | A 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
Name | Type | Description |
---|---|---|
hex | string | A hex-encoded address string. |
bech32Hrp | string | The 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
Name | Type | Description |
---|---|---|
aliasId | string | An Alias ID. |
bech32Hrp | string | The 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
Name | Type | Description |
---|---|---|
nftId | string | An NFT ID. |
bech32Hrp | string | The 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
Name | Type | Description |
---|---|---|
hex | string | A hex-encoded public key. |
bech32Hrp | string | The 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
Name | Type | Description |
---|---|---|
address | string | An address string. |
Returns
boolean
hashTransactionEssence
▸ Static
hashTransactionEssence(essence
): string
Compute the hash of a transaction essence.
Parameters
Name | Type | Description |
---|---|---|
essence | TransactionEssence | A 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
Name | Type | Description |
---|---|---|
signature | Ed25519Signature | An Ed25519 signature. |
message | string | A hex-encoded message. |
Returns
boolean
verifySecp256k1EcdsaSignature
▸ Static
verifySecp256k1EcdsaSignature(publicKey
, signature
, message
): boolean
Verify a Secp256k1Ecdsa signature against a message.
Parameters
Name | Type | Description |
---|---|---|
publicKey | string | A hex-encoded public key. |
signature | string | A hex-encoded signature. |
message | string | A hex-encoded message. |
Returns
boolean
verifyMnemonic
▸ Static
verifyMnemonic(mnemonic
): void
Verify if a mnemonic is a valid BIP39 mnemonic.
Parameters
Name | Type | Description |
---|---|---|
mnemonic | string | A mnemonic string. |
Returns
void