2.1.1 • Published 5 months ago
@hsuite/helpers v2.1.1
@helpers Library
A comprehensive collection of helper utilities for working with blockchain services, transactions, and configurations. This library provides a set of tools to simplify common operations and standardize interactions with various blockchain networks, including Hedera Hashgraph and Ripple (XRP).
Features
Ledger Management
- Singleton pattern implementation for ledger instances
- Unified interface for multiple blockchain networks
- Type-safe configuration management
- Automatic client initialization and management
Transaction Management
- Process and parse different types of transfers (HBAR, XRP, tokens, NFTs)
- Handle offline transaction workflows
- Support multi-signature operations
- Transaction ID generation and management
- Transaction byte conversion for offline signing
Client Configuration
- Network selection (Testnet/Mainnet)
- Operator account management
- Mirror node connectivity
- Automatic network updates
- Client instance lifecycle management
RESTful API Integration
- Authenticated mirror node interactions
- Standardized request/response handling
- Error management and logging
- API key support
Installation
npm install @helpersUsage
Ledger Initialization
Initialize and use ledger instances with the singleton pattern:
import { HashgraphLedger, RippleLedger } from '@helpers';
// Initialize Hashgraph ledger
const hashgraphLedger = HashgraphLedger.initialize({
network: LedgerNetwork.HEDERA_TESTNET,
credentials: {
accountId: '0.0.123456',
privateKey: 'your-private-key'
},
options: {
mirrorNode: {
grpc: 'mirror-node-url'
}
}
});
// Get client instance
const client = await hashgraphLedger.getClient();
// Initialize Ripple ledger
const rippleLedger = RippleLedger.initialize({
network: 'wss://s.altnet.rippletest.net:51233',
credentials: {
secret: 'your-secret-key'
}
});
// Get client instance
const rippleClient = await rippleLedger.getClient();Transaction Management
Handle transactions and transfers:
// Get ledger instance
const ledger = HashgraphLedger.getInstance();
// Get account balance
const balance = await ledger.getBalance('0.0.123456');
// Send transaction
const txId = await ledger.sendTransaction({
from: '0.0.123456',
to: '0.0.789012',
amount: 100,
privateKey: 'your-private-key'
});
// Get transaction details
const txDetails = await ledger.getTransaction(txId);Multi-signature Operations
Generate and manage multi-signature setups:
const ledger = HashgraphLedger.getInstance();
// Generate multi-signature key list
const keyList = await ledger.generateMultisigOfMultisig(
nodes,
threshold,
smartAppPublicKey
);
// Convert transaction to bytes for offline signing
const txBytes = await ledger.makeBytes(
node,
transaction,
accountId,
transactionId
);Network Status
Check network status and connection information:
const ledger = HashgraphLedger.getInstance();
const status = await ledger.getNetworkStatus();
console.log(status);
// {
// network: 'testnet',
// operator: '0.0.123456',
// isConnected: true
// }API Reference
HashgraphLedger
static initialize(config): Initialize the ledger instancestatic getInstance(): Get the singleton instancegetClient(): Get the configured Hedera clientgetBalance(address): Get account balancesendTransaction(transaction): Send a transactiongetTransaction(transactionId): Get transaction detailsgetNetworkStatus(): Get network statusgenerateMultisigOfMultisig(nodes, threshold, smartAppPublicKey?): Generate multi-signature setupmakeBytes(node, transaction, accountId, transactionId?): Convert transaction to bytes
RippleLedger
static initialize(config): Initialize the ledger instancestatic getInstance(): Get the singleton instancegetClient(): Get the configured XRPL clientgetWallet(): Get the Ripple wallet instancegetBalance(address): Get account balancesendTransaction(transaction): Send a transactiongetTransaction(transactionId): Get transaction detailsgetNetworkStatus(): Get network status
Contributing
Please read our contributing guidelines and code of conduct before submitting pull requests or issues.
License
This project is licensed under the terms specified in the LICENSE file.