iso-filecoin
Version:
Isomorphic filecoin abstractions for RPC, signatures, address, token and wallet
157 lines • 4.47 kB
TypeScript
/**
* Get network prefix from network
*
* @param {import("./types.js").Network} network
* @example
* ```ts twoslash
* import { getNetworkPrefix } from 'iso-filecoin/utils'
*
* const prefix = getNetworkPrefix('mainnet')
* // => 'f'
*/
export function getNetworkPrefix(network: import("./types.js").Network): "f" | "t";
/**
* Get network from prefix
*
* @param {NetworkPrefix} networkPrefix
* @returns {import('./types').Network}
* @example
* ```ts twoslash
* import { getNetwork } from 'iso-filecoin/utils'
*
* const network = getNetwork('f')
* // => 'mainnet'
*/
export function getNetwork(networkPrefix: NetworkPrefix): import("./types").Network;
/**
* Returns the third position from derivation path
*
* @param {string} path - path to parse
* @returns {import('./types.js').Network}
* @example
* ```ts twoslash
* import { getNetworkFromPath } from 'iso-filecoin/utils'
*
* const network = getNetworkFromPath("m/44'/461'/0'/0/0")
* // => 'testnet'
*/
export function getNetworkFromPath(path: string): import("./types.js").Network;
/**
* Get network from any chain designation
*
* @param {number | string} chainId
*/
export function getNetworkFromChainId(chainId: number | string): "mainnet" | "testnet";
/**
* Derivation path from chain
*
* @param {import('./types').Network} network
* @param {number} [index=0] - Account index (default 0)
* @example
* ```ts twoslash
* import { pathFromNetwork } from 'iso-filecoin/utils'
*
* const path = pathFromNetwork('mainnet')
* // => 'm/44'/461'/0'/0/0'
*/
export function pathFromNetwork(network: import("./types").Network, index?: number): string;
/**
* Checks if the prefix is a valid network prefix
*
* @param {string} prefix
* @returns {prefix is NetworkPrefix}
* @example
* ```ts twoslash
* import { checkNetworkPrefix } from 'iso-filecoin/utils'
*
* checkNetworkPrefix('f') // true
* checkNetworkPrefix('t') // true
* checkNetworkPrefix('x') // false
* ```
*/
export function checkNetworkPrefix(prefix: string): prefix is NetworkPrefix;
/**
* Parse a derivation path into its components
*
* @see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#path-levels
* @param {string} path - The derivation path to parse
* @returns {import('./types').DerivationPathComponents} An object containing the derivation path components
* @example
* ```ts twoslash
* import { parseDerivationPath } from 'iso-filecoin/utils'
*
* const components = parseDerivationPath("m/44'/461'/0'/0/0")
* // {
* // purpose: 44,
* // coinType: 461,
* // account: 0,
* // change: 0,
* // addressIndex: 0
* // }
* ```
*/
export function parseDerivationPath(path: string): import("./types").DerivationPathComponents;
/**
* Checksum ethereum address
*
* @param {string} address - Ethereum address
* @returns {string} Checksummed ethereum address
* @example
* ```ts twoslash
* import { checksumEthAddress } from 'iso-filecoin/utils'
*
* const address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359'
* const checksummed = checksumEthAddress(address)
* // => '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
* ```
*/
export function checksumEthAddress(address: string): string;
/**
* Get cache instance from cache config
*
* @param {import('./types').Cache} cache - Cache config
* @returns {import('iso-kv').KV}
* @example
* ```js
* import { getCache } from 'iso-filecoin'
* import { MemoryDriver } from 'iso-kv/drivers/memory.js'
*
* // use default memory driver
* const cache = getCache(true)
*
* // use custom driver
* const customCache = getCache(new MemoryDriver())
* ```
*/
export function getCache(cache: import("./types").Cache): import("iso-kv").KV;
/**
* Create a Lotus CID from a Uint8Array
*
* @param {Uint8Array} data
* @example
* ```js
* import { lotusCid } from 'iso-filecoin/utils'
*
* const data = new Uint8Array([1, 2, 3])
* const cid = lotusCid(data)
* ```
*/
export function lotusCid(data: Uint8Array): Uint8Array<ArrayBuffer>;
/**
* Check if an error is a ZodError
*
* @param {unknown} err
* @returns {err is import('zod/v4').ZodError}
*/
export function isZodErrorLike(err: unknown): err is import("zod/v4").ZodError;
export namespace SIGNATURES {
let SECP256K1: 1;
let BLS: 3;
}
export namespace NETWORKS {
let mainnet: "f";
let testnet: "t";
}
export const BIP_32_PATH_REGEX: RegExp;
export type NetworkPrefix = import("./types").NetworkPrefix;
//# sourceMappingURL=utils.d.ts.map