import { BaseUtils, KeyPair, Recipient } from '@bitgo/sdk-core'; import { Principal as DfinityPrincipal } from '@dfinity/principal'; import { HttpCanisterUpdate, IcpTransactionData, Signatures, MetaData, SendArgs, PayloadsData, AccountIdentifierHash } from './iface'; import BigNumber from 'bignumber.js'; export declare class Utils implements BaseUtils { /** @inheritdoc */ isValidSignature(signature: string): boolean; /** * gets the fee data of this transaction. */ feeData(): string; /** * Checks if the provided address is a valid ICP address. * * @param {string} address - The address to validate. * @returns {boolean} - Returns `true` if the address is valid, otherwise `false`. */ isValidAddress(address: string): boolean; /** * Validates the memo ID in the address and returns the root address. * * @param {string} address - The address to validate and extract the root address from. * @returns {string | undefined} - The root address if valid, otherwise `undefined`. */ validateMemoAndReturnRootAddress(address: string): string | undefined; /** * Checks if the provided hex string is a valid public key. * * A valid public key can be either compressed or uncompressed: * - Compressed public keys are 33 bytes long and start with either 0x02 or 0x03. * - Uncompressed public keys are 65 bytes long and start with 0x04. * * @param {string} hexStr - The hex string representation of the public key to validate. * @returns {boolean} - Returns `true` if the hex string is a valid public key, otherwise `false`. */ isValidPublicKey(hexStr: string): boolean; /** * Encodes a value into CBOR format and returns it as a hex string. * * @param {unknown} value - The value to encode. * @returns {string} - The CBOR encoded value as a hex string. */ cborEncode(value: unknown): string; /** * Checks if the length of the given hexadecimal string is valid. * A valid length is either 66 characters (33 bytes) or 130 characters (65 bytes). * * @param {string} hexStr - The hexadecimal string to check. * @returns {boolean} - Returns `true` if the length is valid, otherwise `false`. */ isValidLength(hexStr: string): boolean; /** * Checks if the provided string is a valid hexadecimal string. * * A valid hexadecimal string consists of pairs of hexadecimal digits (0-9, a-f, A-F). * * @param hexStr - The string to be validated as a hexadecimal string. * @returns True if the string is a valid hexadecimal string, false otherwise. */ isValidHex(hexStr: string): boolean; /** * Converts a hexadecimal string to a Uint8Array. * * @param {string} hex - The hexadecimal string to convert. * @returns {Uint8Array} The resulting byte array. */ hexToBytes(hex: string): Uint8Array; /** @inheritdoc */ isValidPrivateKey(key: string): boolean; /** * Validates whether the provided key is a valid ICP private key. * * This function attempts to create a new instance of `IcpKeyPair` using the provided key. * If the key is valid, the function returns `true`. If the key is invalid, an error is thrown, * and the function returns `false`. * * @param {string} key - The private key to validate. * @returns {boolean} - `true` if the key is valid, `false` otherwise. */ isValidKey(key: string): boolean; /** * Compresses an uncompressed public key. * * @param {string} uncompressedKey - The uncompressed public key in hexadecimal format. * @returns {string} - The compressed public key in hexadecimal format. * @throws {Error} - If the input key is not a valid uncompressed public key. */ compressPublicKey(uncompressedKey: string): string; /** * Converts a public key from its hexadecimal string representation to DER format. * * @param {string} publicKeyHex - The public key in hexadecimal string format. * @returns The public key in DER format as a Uint8Array. */ getPublicKeyInDERFormat(publicKeyHex: string): Uint8Array; /** * Converts a public key in hexadecimal format to a Dfinity Principal ID. * * @param {string} publicKeyHex - The public key in hexadecimal format. * @returns The corresponding Dfinity Principal ID. */ getPrincipalIdFromPublicKey(publicKeyHex: string): DfinityPrincipal; /** * Derives a DfinityPrincipal from a given public key in hexadecimal format. * * @param {string} publicKeyHex - The public key in hexadecimal format. * @returns The derived DfinityPrincipal. * @throws Will throw an error if the principal cannot be derived from the public key. */ derivePrincipalFromPublicKey(publicKeyHex: string): DfinityPrincipal; /** * Converts a DfinityPrincipal and an optional subAccount to a string representation of an account ID. * * @param {DfinityPrincipal} principal - The principal to convert. * @param {Uint8Array} [subAccount=new Uint8Array(32)] - An optional sub-account, defaults to a 32-byte array of zeros. * @returns {string} The hexadecimal string representation of the account ID. */ fromPrincipal(principal: DfinityPrincipal, subAccount?: Uint8Array): string; getAccountIdFromPrincipalBytes(ACCOUNT_ID_PREFIX: Buffer, principalBytes: Buffer, subAccount: Uint8Array): string; /** * Retrieves the address associated with a given hex-encoded public key. * * @param {string} hexEncodedPublicKey - The public key in hex-encoded format. * @returns {string} The address derived from the provided public key. * @throws {Error} Throws an error if the provided public key is not in a valid hex-encoded format. */ getAddressFromPublicKey(hexEncodedPublicKey: string): string; /** * Generates a new key pair. If a seed is provided, it will be used to generate the key pair. * * @param {Buffer} [seed] - Optional seed for key generation. * @returns {KeyPair} - The generated key pair containing both public and private keys. * @throws {Error} - If the private key is missing in the generated key pair. */ generateKeyPair(seed?: Buffer): KeyPair; /** * Validates the provided fee. * * @param {string} fee - The fee to validate. * @throws {BuildTransactionError} - If the fee is zero or invalid. */ validateFee(fee: string): boolean; /** @inheritdoc */ validateValue(value: BigNumber): boolean; /** * Validates the provided memo. * * @param {number | BigInt} memo - The memo to validate. * @returns {boolean} - Returns `true` if the memo is valid. * @throws {BuildTransactionError} - If the memo is invalid. */ validateMemo(memo: number | BigInt): boolean; validateExpireTime(expireTime: number | BigInt): boolean; /** * Validates the raw transaction data to ensure it has a valid format in the blockchain context. * * @param {IcpTransactionData} transactionData - The transaction data to validate. * @throws {ParseTransactionError} If the transaction data is invalid. */ validateRawTransaction(transactionData: IcpTransactionData): void; /** * * @param {object} update * @returns {Buffer} */ generateHttpCanisterUpdateId(update: HttpCanisterUpdate): Buffer; /** * Generates a representation-independent hash for an HTTP canister update. * * @param {HttpCanisterUpdate} update - The HTTP canister update object. * @returns {Buffer} - The hash of the update object. */ HttpCanisterUpdateRepresentationIndependentHash(update: HttpCanisterUpdate): Buffer; /** * Generates a SHA-256 hash for a given map object. * * @param {Record} map - The map object to hash. * @returns {Buffer} - The resulting hash as a Buffer. */ hashOfMap(map: Record): Buffer; /** * Generates a hash for a key-value pair. * * @param {string} key - The key to hash. * @param {string | Buffer | BigInt} val - The value to hash. * @returns {Buffer} - The resulting hash as a Buffer. */ hashKeyVal(key: string, val: any): Buffer; /** * Generates a SHA-256 hash for a given string. * * @param {string} value - The string to hash. * @returns {Buffer} - The resulting hash as a Buffer. */ hashString(value: string): Buffer; /** * Generates a hash for a 64-bit unsigned integer. * * @param {bigint} n - The 64-bit unsigned integer to hash. * @returns {Buffer} - The resulting hash as a Buffer. */ hashU64(n: bigint): Buffer; /** * Generates a SHA-256 hash for an array of elements. * * @param {Array} elements - The array of elements to hash. * @returns {Buffer} - The resulting hash as a Buffer. */ hashArray(elements: Array): Buffer; /** * Generates a hash for a given value. * * @param {string | Buffer | BigInt | number | Array} val - The value to hash. * @returns {Buffer} - The resulting hash as a Buffer. * @throws {Error} - If the value type is unsupported. */ hashVal(val: string | Buffer | BigInt | number | Array): Buffer; /** * Computes the SHA-256 hash of the given buffer. * * @param value - The buffer to hash. * @returns The SHA-256 hash of the input buffer. */ hashBytes(value: Buffer | Uint8Array): Buffer; /** * Computes the SHA-256 hash of the provided array of Buffer chunks. * * @param {Array} chunks - An array of Buffer objects to be hashed. * @returns {Buffer} - The resulting SHA-256 hash as a Buffer. */ sha256(chunks: Array | Array): Buffer; /** * Converts a hexadecimal string to a Buffer. * * @param hex - The hexadecimal string to convert. * @returns A Buffer containing the binary data represented by the hexadecimal string. */ blobFromHex(hex: string): Buffer; /** * Converts a binary blob (Buffer) to a hexadecimal string. * * @param {Buffer} blob - The binary data to be converted. * @returns {string} The hexadecimal representation of the binary data. */ blobToHex(blob: Buffer): string; /** * Decodes a given CBOR-encoded buffer. * * @param buffer - The CBOR-encoded buffer to decode. * @returns The decoded data. */ cborDecode(buffer: Buffer): unknown; /** * Generates a Buffer containing the domain IC request string. * * @returns {Buffer} A Buffer object initialized with the string '\x0Aic-request'. */ getDomainICRequest(): Buffer; /** * Combines the domain IC request buffer with the provided message ID buffer to create signature data. * * @param {Buffer} messageId - The buffer containing the message ID. * @returns {Buffer} - The concatenated buffer containing the domain IC request and the message ID. */ makeSignatureData(messageId: Buffer): Buffer; /** * Extracts the recipient information from the provided ICP transaction data. * * @param {IcpTransactionData} icpTransactionData - The ICP transaction data containing the receiver's address and amount. * @returns {Recipient[]} An array containing a single recipient object with the receiver's address and amount. */ getRecipients(icpTransactionData: IcpTransactionData): Recipient; getTransactionSignature(signatureMap: Map, update: HttpCanisterUpdate): Signatures | undefined; getMetaData(memo: number | BigInt, timestamp: number | bigint | undefined, ingressEnd: number | BigInt | undefined): { metaData: MetaData; ingressEndTime: number | BigInt; }; convertSenderBlobToPrincipal(senderBlob: Uint8Array): Uint8Array; fromArgs(arg: Uint8Array): SendArgs; toArg(args: SendArgs): Promise; getAccountIdPrefix(): Buffer; /** @inheritdoc */ isValidBlockId(hash: string): boolean; /** * Returns whether or not the string is a valid ICP hash * * @param {string} hash - string to validate * @returns {boolean} */ isValidHash(hash: string): boolean; /** @inheritdoc */ isValidTransactionId(txId: string): boolean; getSignatures(payloadsData: PayloadsData, senderPublicKey: string, senderPrivateKey: string): Signatures[]; signPayload: (privateKey: string, payloadHex: string) => string; getTransactionId(unsignedTransaction: string, senderAddress: string, receiverAddress: string): string; safeBigInt(value: unknown): number | bigint; generateTransactionHash(sendArgs: SendArgs, senderAddress: string, receiverAddress: string): string; accountIdentifier(accountAddress: string): AccountIdentifierHash; getProcessedTransactionMap(txnMap: Map): Map; serializeAccountIdentifier(accountHash: AccountIdentifierHash): string; } declare const utils: Utils; export default utils; //# sourceMappingURL=utils.d.ts.map