Utils
Auto-Utils Package Documentation
Introduction
The @autonomys/auto-utils
package provides core utility functions for interacting with the Autonomys Network. It offers functionalities for:
- Wallet Management: Initialize and manage wallets using mnemonics or URIs.
- Network Configuration: Access and manage network and domain settings.
- Data Storage: Save and read data to and from local storage or the file system.
- Cryptographic Operations: Perform hashing and data manipulation using cryptographic functions.
- API Activation: Activate and manage connections to the Autonomys Network APIs.
- Address Utilities: Convert and decode addresses to and from standardized formats.
This package serves as the foundational layer for building applications within the Autonomys ecosystem.
Installation
Install the package via npm or yarn:
# Using npm
npm install @autonomys/auto-utils
# Using yarn
yarn add @autonomys/auto-utils
Importing the Package
Before using the functions provided by the auto-utils
package, you need to import them into your project:
// Import specific functions
import { activateWallet, activate, blake2b_256 } from '@autonomys/auto-utils';
// Or import everything
import * as utils from '@autonomys/auto-utils';
Available Functions
Account Utilities
createAccountIdType(api, address): Uint8Array
: Creates anAccountId
object from an address.
Event Utilities
Type
: Enum for event types (e.g.,system
).eventName(type, event): string
: Combines type and event to a full event name.eventsGroup
: Groups system events by name.expectSuccessfulTxEvent
: Default success event names array.
Transaction Utilities
signAndSendTx(sender, tx, options?, eventsExpected?, log?, mapErrorCodeToEnum?): Promise<TransactionSignedAndSend>
: Signs, sends, and validates a transaction.
Signing Utilities
signMessage(signer, address, data): Promise<{ signature: string }>
: Signs a message with a signer and address.signingKey(publicKey): string
: Converts a public key to a hex string.signatureVerify
: Verifies signatures (re-exported from@polkadot/util-crypto
).
Event Validation
validateEvents(events, eventsExpected?, tx, block, log?): EventsValidated
: Checks if expected events are in transaction events.
Utility Functions
isAddress(address): boolean
: Validates a Substrate address.isHex(value): boolean
: Validates a hexadecimal string.
Wallet Management
activate(options?): Promise<ApiPromise>
: Connects to the Autonomys Network.activateWallet(options): Promise<{ api, accounts }>
: Activates a wallet using mnemonic or URI.mockWallets(options, api?): Promise<Wallet[]>
: Creates mock wallets for testing.getMockWallet(name, wallets): Wallet
: Retrieves a mock wallet by name.
Network Management
networks
: Array of available networks.getNetworkDetails(options): NetworkDetails
: Gets details of a network.getNetworkDomainDetails(options): DomainDetails
: Gets details of a domain.
Cryptographic Functions
blake2b_256(data): string
: Hashes data with BLAKE2b-256.stringToUint8Array(string): Uint8Array
: Converts a string toUint8Array
.concatenateUint8Arrays(...arrays): Uint8Array
: Concatenates multipleUint8Array
s.
Data Storage
save(key, value): void
: Saves data locally.read(key): any
: Reads data from local storage.