Skip to content

Utilities

Keys


generateKeys ( mnemonic?: string, path?: string ) ⇒ Promise< KeyGenerationResult >

Generates both Ethereum and Cosmos key pairs from a given or newly generated mnemonic phrase and derivation path.



generateSingleUseEthKeypair ( ethXPrivKey: string, uuid: string ) ⇒ Promise < KeyPairDetails >

Derives a single-use Ethereum key pair (private key, public key, and address) from an extended private key and a UUID.



generateSingleUseEthPubKey ( ethXPubKey: string, uuid: string ) ⇒ Promise < KeyPairDetails >

Derives a single-use Ethereum public key and address from an extended public key and a UUID.



hashUUIDToHDAddrIndex ( uuid: string ) ⇒ string

Maps a UUID v4 to a 32-bit integer which is used to derive a specific hierarchical deterministic (HD) address index for key derivation.

DLPC


generateDlpcDocumentHash ( input: {
originatorId: string;
referenceId: string;
committer: string;
committee: string;
denom: string;
amount: number;
commitmentDate: number;
dueDate: number;
applicableRules: string;
} ) ⇒ Buffer

Generates a SHA-256 hash of a DLPC document based on the provided inputs.



predictContractAddress ( input: any, factoryAddress: string, salt: string ) ⇒ Promise<string>

Predicts the contract address that will be created using the CREATE2 opcode.



generateConditionId ( condition: string ) ⇒ string

Generates a keccak256 hash for a given condition string.



eventFormatter ( event: any ) ⇒ string

Formats DLPC-related events into human-readable strings for logging or display purposes.



getUpdateTypeNumber ( updateType: keyof typeof UpdateTypeEnum ) ⇒ number

Retrieves the corresponding numeric value for a given update type from the UpdateTypeEnum enum.



getFromValue ( fromValue: "bytes32" | "address" ) ⇒ string

Encodes the value for a given type ("bytes32" or "address") and returns the encoded value.

DID Registry


generateDid ( publicKey: string, rpcUrl: string, chainId: number | string ) ⇒ Promise< EthrDID >

Generates a DID using the provided public key, RPC URL, and chain ID.



getDidEventDetails ( data_events: any[], eventName: string, eventStruct: any )

Retrieves and processes event details for a specified DID event. Decodes specific fields and validates attributes based on the event type.



getDidEvents ( contract: any, identity: string, eventStruct: any )

Retrieves and processes past events from a smart contract, filtered by a specified identity.



processSetAttributeEvents ( dIdAttributeChangedEvents: any )

Processes DIDAttributeChanged events and consolidates them into a single result object.

Transactions


prepareDeployTx ( constructorParams: any[], contractFactory: ethers.ContractFactory, signerAddress: string, provider: ethers.Provider ) ⇒ Promise<TxData>

Prepares transaction data for deploying a new contract.



prepareTxData ( contract: ethers.Contract, method: string, args: any[], signerAddress: string, provider: ethers.Provider ) ⇒ Promise<TxData>

Prepares the transaction data for invoking a method on the contract by generating the required data.



prepareEthTransferTxData ( fromAddress: string, toAddress: string, amountEther: string, provider: ethers.Provider) ⇒ Promise<TxData>

Prepares transaction data for transferring Ether between addresses.



prepareSignedTxData ( unsignedTx: any, privKey: string, provider: ethers.Provider ) ⇒ Promise<string>

Prepares and signs transaction data using a private key.

Logs Decoder


decodeLogs ( logs: any[], methodIDs: any, tokenAddress: string ) ⇒ any[]

Decodes logs based on provided method IDs and token address. Filters logs, decodes them using method IDs, and checks for the token address in the decoded events.



tryDecodeLogs ( method: any, logItem: any ) ⇒ any | null

Attempts to decode a log item using a specific method. Decodes log data and topics based on the method's input parameters.



containsTokenAddress ( events: any[], tokenAddress: string ) ⇒ boolean

Checks if the decoded events contain the specified token address. Searches through the events to find if any of them match the given token address.



decodeLogsFromReceipt ( receipt: any ) ⇒ Promise < any[] >

Decodes logs from a transaction receipt. Returns a promise that resolves to an array of decoded logs.



filterEventsByIdentity ( events: any, identity: string ) ⇒ any[]

Filters events by identity. Returns an array of events where the returnValues.identity matches the specified identity.

ABI


addABI ( abiArray: any[] ) ⇒ any

Generates a mapping of method IDs from an ABI array. Processes the ABI array to create a mapping of method IDs to their respective ABI definitions.



getEventsFromAbi ( abi: any ) ⇒ Promise< any[]

Retrieves events from an ABI definition. Returns an array of event objects from the ABI.



getEventStruct ( events: any ) ⇒ Promise< any

Extracts event structures from ABI events. Returns an object where each key is an event name and each value is an array of event input names.



typeToString ( input: any ) ⇒ string

Converts a type object into its string representation.

Math Helpers


safeBigIntToNumber ( value: bigint ) ⇒ number

Safely converts a BigInt value to a number, ensuring it falls within the safe integer range.



generateSalt ( input: string ) ⇒ string

Generates a sha256 hash of the input passed. Returns the sha256 hash salt based on the input.



ethereumAddressToDecimal ( address: string ) ⇒ string

Converts an Ethereum address to its decimal representation as a string.



replacer ( key: any, value: any ) ⇒ any

Replaces bigint values with their string representation during JSON serialization. Returns the processed value, converted to a string if it's a bigint.

String & Data Manipulation


transformDatastore ( dataStore: string ) ⇒ string

Transforms a datastore name into its corresponding collection name. Throws an error if the datastore name is unknown.



trimNullCharacters ( str: string ) ⇒ string

Removes trailing null characters (\u0000) from a string.

Network & Request


handleAxiosError ( error: any ) ⇒ void

Handles and logs errors from Axios requests. Processes different types of errors that may occur during an Axios request, including HTTP errors, network errors, and other types of errors.



fundAccount ( faucetUrl: string, address: string ) ⇒ Promise < any >

Funds an account using a specified faucet URL. Returns the response data from the faucet service.

Random Generators


generateRandomListingId () ⇒ Promise<string>

Generates a random listing ID consisting of 64 hexadecimal characters.



generateOfferId ( length?: number ) ⇒ Promise<string>

Generates a random offer ID of a specified length. Defaults to 24 characters.

Date & Time


isValidDate ( timestamp: any ) ⇒ boolean

Validates if the provided Unix timestamp is a date that is today or in the future. Converts the Unix timestamp to a JavaScript Date object, compares it with today's date.