util
Utility functions for CESS SDK
Installation
npm install @cessnetwork/utilOverview
The @cessnetwork/util package provides a comprehensive set of utility functions for working with the CESS (Cumulus Encrypted Storage System) network. This package includes utilities for:
Account management and address validation
Cryptographic operations and signing
File hashing and integrity verification
Network operations
Data formatting and conversion
Error handling
Core Modules
Account Utilities
Functions for managing CESS accounts, validating addresses, and converting between different formats.
Signing Utilities
Functions for signing messages and verifying signatures using mnemonics and cryptographic keys.
Hash Utilities
Functions for calculating file and data hashes.
API Reference
Account Functions
parsePublicKey(address: string): Uint8Array- Parse public key from addressencodePublicKeyAsTestNetAddr(publicKey: Uint8Array): string- Encode public key as testnet address (ss58Format: 11330)encodePublicKeyAsMainNetAddr(publicKey: Uint8Array): string- Encode public key as mainnet address (ss58Format: 11331)validateAddress(address: string, ss58Format?: number): boolean- Validate address with optional ss58Format checkconvertAddressFormat(address: string, targetSs58Format: number): string- Convert address to specified ss58FormatconvertAddrToMainNet(address: string): string- Convert address from ss58Format 11330 to 11331 (cX... -> ce...)convertAddrToTestNet(address: string): string- Convert address from ss58Format 11331 to 11330 (ce... -> cX...)evmAddrToCessAddr(evmAddr: string, targetSs58Format: number): string- Convert Ethereum address to CESS address with specified ss58Format
Signing Functions
safeSignUnixTime(unixTime: string | number, mnemonic: string): Uint8Array- Sign a current unix time with a mnemonic using SR25519getWrappedMsg(unixTime: string | number): Uint8Array- Wrap a unix time message with tagssr25519SignWithMnemonic(mnemonic: string, msg: string): Uint8Array- Sign a message with a mnemonic using SR25519verifySignature(msg: string | Uint8Array, sign: Uint8Array, account: string): boolean- Verify a signature with a public keyparseEvmAccFromEvmSign(message: string, sign: string): string- Parse Ethereum account from Ethereum signature
Hash Functions
calcSHA256(data: Buffer): string- Calculate SHA256 hash of buffer datacalcPathSHA256(filePath: string): Promise<string>- Calculate SHA256 hash of a filecalcFileSHA256(stream: NodeJS.ReadableStream): Promise<string>- Calculate SHA256 hash of a streamcalcMD5(data: string): string- Calculate MD5 hash of string datacalcPathSHA256Bytes(filePath: string): Promise<Buffer>- Calculate SHA256 hash as BuffercalcFileSHA256Bytes(stream: NodeJS.ReadableStream): Promise<Buffer>- Calculate SHA256 hash of stream as Buffer
File Functions
getFileSize(filePath: string): number- Get the size of a filereadChunk(filePath: string, start: number, end: number): Promise<Buffer>- Read a chunk of a fileensureDir(dirPath: string): void- Ensure directory exists
Network Functions
checkConnectivity(host: string, port: number): Promise<boolean>- Check network connectivitypingHost(host: string): Promise<PingResponse>- Ping a host
String Functions
toBase64(data: string): string- Convert string to base64fromBase64(data: string): string- Convert base64 to stringtoHex(data: string): string- Convert string to hexfromHex(data: string): string- Convert hex to string
Time Functions
formatTimestamp(timestamp: number): string- Format timestamp to readable stringgetCurrentTimestamp(): number- Get current timestamp
Gateway Utilities
The utility functions play a critical role in gateway operations, particularly for authentication and communication with the CESS storage network.
Gateway Authentication Functions
When interacting with CESS gateways, you need specific utilities to sign messages and authenticate:
Last updated
Was this helpful?

