# Class: MoneroUtils

## MoneroUtils

Collection of Monero utilities. Runs in a worker thread by default.

Source:
  - src/main/js/common/MoneroUtils.js, line 14

### Methods

#### (static) atomicUnitsToXmr(amountAtomicUnits) → {number}

Convert atomic units to XMR.

##### Parameters:

Name | Type | Description
--- | --- | ---
`amountAtomicUnits` | BigInteger | string | amount in atomic units to convert to XMR

Source:
  - src/main/js/common/MoneroUtils.js, line 435

##### Returns:

amount in XMR

Type
  number

#### (async, static) binaryBlocksToJson(uint8arr) → {Promise.<object>}

Convert the binary response from daemon RPC block retrieval to JSON.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uint8arr` | Uint8Array | binary response from daemon RPC when getting blocks

Source:
  - src/main/js/common/MoneroUtils.js, line 377

##### Returns:

JSON object with the blocks data

Type
  Promise.<object>

#### (async, static) binaryToJson(uint8arr) → {Promise.<object>}

Convert the given portable storage binary to JSON.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uint8arr` | Uint8Array | binary data in Monero's portable storage format

Source:
  - src/main/js/common/MoneroUtils.js, line 340

##### Returns:

JSON object converted from the binary data

Type
  Promise.<object>

#### (async, static) getIntegratedAddress(networkType, standardAddress, paymentId) → {Promise.<MoneroIntegratedAddress>}

Get an integrated address.

##### Parameters:

Name | Type | Description
--- | --- | ---
`networkType` | MoneroNetworkType | network type of the integrated address
`standardAddress` | string | address to derive the integrated address from
`paymentId` | string | optionally specifies the integrated address's payment id (defaults to random payment id)

Source:
  - src/main/js/common/MoneroUtils.js, line 151

##### Returns:

the integrated address

Type
  Promise.<MoneroIntegratedAddress>

#### (async, static) getLastTxPubKey(byte[]opt) → {string}

Decode tx extra according to https://cryptonote.org/cns/cns005.txt and returns the last tx pub key. TODO: use c++ bridge for this

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`byte[]` |  | <optional> | txExtra - array of tx extra bytes

Source:
  - src/main/js/common/MoneroUtils.js, line 248

##### Returns:

the last pub key as a hexidecimal string

Type
  string

#### (static) getVersion() → {string}

Get the version of the monero-javascript library.

Source:
  - src/main/js/common/MoneroUtils.js, line 21

##### Returns:

the version of this monero-javascript library

Type
  string

#### (async, static) isValidAddress(address, networkType) → {Promise.<boolean>}

Determine if the given address is valid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`address` | string | address
`networkType` | MoneroNetworkType | network type of the address to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 178

##### Returns:

true if the address is valid, false otherwise

Type
  Promise.<boolean>

#### (async, static) isValidPaymentId(paymentId) → {Promise.<bool>}

Determine if the given payment id is valid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`paymentId` | string | payment id to determine if valid

Source:
  - src/main/js/common/MoneroUtils.js, line 218

##### Returns:

true if the payment id is valid, false otherwise

Type
  Promise.<bool>

#### (async, static) isValidPrivateSpendKey(privateSpendKey) → {Promise.<bool>}

Indicates if a private spend key is valid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`privateSpendKey` | string | is the private spend key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 83

##### Returns:

true if the private spend key is valid, false otherwise

Type
  Promise.<bool>

#### (async, static) isValidPrivateViewKey(privateViewKey) → {Promise.<bool>}

Indicates if a private view key is valid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`privateViewKey` | string | is the private view key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 53

##### Returns:

true if the private view key is valid, false otherwise

Type
  Promise.<bool>

#### (async, static) isValidPublicSpendKey(publicSpendKey) → {Promise.<bool>}

Indicates if a public spend key is valid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`publicSpendKey` | string | is the public spend key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 98

##### Returns:

true if the public spend key is valid, false otherwise

Type
  Promise.<bool>

#### (async, static) isValidPublicViewKey(publicViewKey) → {Promise.<bool>}

Indicates if a public view key is valid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`publicViewKey` | string | is the public view key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 68

##### Returns:

true if the public view key is valid, false otherwise

Type
  Promise.<bool>

#### (async, static) jsonToBinary(json) → {Promise.<Uint8Array>}

Convert the given JSON to a binary Uint8Array using Monero's portable storage format.

##### Parameters:

Name | Type | Description
--- | --- | ---
`json` | object | json to convert to binary

Source:
  - src/main/js/common/MoneroUtils.js, line 303

##### Returns:

the json converted to portable storage binary

Type
  Promise.<Uint8Array>

#### (static) mergeTx(txs, tx)

Merges a transaction into a list of existing transactions.

##### Parameters:

Name | Type | Description
--- | --- | ---
`txs` | Array.<MoneroTx> | existing transactions to merge into
`tx` | MoneroTx | transaction to merge into the list

Source:
  - src/main/js/common/MoneroUtils.js, line 287

#### (static) paymentIdsEqual(paymentId1, paymentId2) → {bool}

Determines if two payment ids are functionally equal. For example, 03284e41c342f032 and 03284e41c342f032000000000000000000000000000000000000000000000000 are considered equal.

##### Parameters:

Name | Type | Description
--- | --- | ---
`paymentId1` | string | is a payment id to compare
`paymentId2` | string | is a payment id to compare

Source:
  - src/main/js/common/MoneroUtils.js, line 271

##### Returns:

true if the payment ids are equal, false otherwise

Type
  bool

#### (static) setProxyToWorker(proxyToWorker)

Enable or disable proxying these utilities to a worker thread.

##### Parameters:

Name | Type | Description
--- | --- | ---
`proxyToWorker` | boolean | specifies if utilities should be proxied to a worker

Source:
  - src/main/js/common/MoneroUtils.js, line 30

#### (async, static) validateAddress(address, networkType)

Validate the given address, throw an error if invalid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`address` | string | address to validate
`networkType` | MoneroNetworkType | network type of the address to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 193

#### (async, static) validateMnemonic(mnemonic)

Validate the given mnemonic, throw an error if invalid. TODO: improve validation, use network type

##### Parameters:

Name | Type | Description
--- | --- | ---
`mnemonic` | string | mnemonic to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 41

#### (async, static) validatePaymentId(paymentId)

Validate the given payment id, throw an error if invalid. TODO: improve validation

##### Parameters:

Name | Type | Description
--- | --- | ---
`paymentId` | string | payment id to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 234

#### (async, static) validatePrivateSpendKey(privateSpendKey)

Validate the given private spend key, throw an error if invalid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`privateSpendKey` | string | private spend key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 130

#### (async, static) validatePrivateViewKey(privateViewKey)

Validate the given private view key, throw an error if invalid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`privateViewKey` | string | private view key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 112

#### (async, static) validatePublicSpendKey(publicSpendKey)

Validate the given public spend key, throw an error if invalid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`publicSpendKey` | string | public spend key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 139

#### (async, static) validatePublicViewKey(publicViewKey)

Validate the given public view key, throw an error if invalid.

##### Parameters:

Name | Type | Description
--- | --- | ---
`publicViewKey` | string | public view key to validate

Source:
  - src/main/js/common/MoneroUtils.js, line 121

#### (static) xmrToAtomicUnits(amountXmr) → {BigInteger}

Convert XMR to atomic units.

##### Parameters:

Name | Type | Description
--- | --- | ---
`amountXmr` | number | string | amount in XMR to convert to atomic units

Source:
  - src/main/js/common/MoneroUtils.js, line 417

##### Returns:

amount in atomic units

Type
  BigInteger