import { Cell, Hash, Script } from '@ckb-lumos/base'; type Json = Record; interface BaseApis { request(route: string, options?: BaseApiRequestOptions): Promise; post(route: string, options?: BaseApiRequestOptions): Promise; generateToken(): Promise; init(force?: boolean): Promise; } interface BaseApiRequestOptions extends RequestInit { params?: Json; method?: 'GET' | 'POST'; requireToken?: boolean; allow404?: boolean; } interface BtcAssetsApiToken { token: string; } interface BtcAssetsApiContext { request: { url: string; body?: Json; params?: Json; }; response: { status: number; data?: Json | string; }; } interface BtcApis { getBtcBlockchainInfo(): Promise; getBtcBlockByHash(blockHash: string): Promise; getBtcBlockHeaderByHash(blockHash: string): Promise; getBtcBlockHashByHeight(blockHeight: number): Promise; getBtcBlockTransactionIdsByHash(blockHash: number): Promise; getBtcRecommendedFeeRates(): Promise; getBtcBalance(address: string, params?: BtcApiBalanceParams): Promise; getBtcUtxos(address: string, params?: BtcApiUtxoParams): Promise; getBtcTransactions(address: string, params?: BtcApiTransactionParams): Promise; getBtcTransaction(txId: string): Promise; sendBtcTransaction(txHex: string): Promise; } interface BtcApiBlockchainInfo { chain: string; blocks: number; bestblockhash: string; difficulty: number; mediantime: number; } interface BtcApiBlock { id: string; height: number; version: number; timestamp: number; tx_count: number; size: number; weight: number; merkle_root: string; previousblockhash: string; mediantime: number; nonce: number; bits: number; difficulty: number; } interface BtcApiBlockHash { hash: string; } interface BtcApiBlockHeader { header: string; } interface BtcApiBlockTransactionIds { txids: string[]; } interface BtcApiRecommendedFeeRates { fastestFee: number; halfHourFee: number; hourFee: number; economyFee: number; minimumFee: number; } interface BtcApiBalanceParams { min_satoshi?: number; no_cache?: boolean; } interface BtcApiBalance { address: string; satoshi: number; total_satoshi: number; available_satoshi: number; pending_satoshi: number; rgbpp_satoshi: number; dust_satoshi: number; utxo_count: number; } interface BtcApiUtxoParams { only_non_rgbpp_utxos?: boolean; only_confirmed?: boolean; min_satoshi?: number; no_cache?: boolean; } interface BtcApiUtxo { txid: string; vout: number; value: number; status: { confirmed: boolean; block_height: number; block_hash: string; block_time: number; }; } interface OfflineBtcUtxo extends BtcApiUtxo { address: string; nonRgbpp: boolean; } interface BtcApiSentTransaction { txid: string; } interface BtcApiTransactionParams { after_txid?: string; } interface BtcApiTransaction { txid: string; version: number; locktime: number; vin: { txid: string; vout: number; prevout: { scriptpubkey: string; scriptpubkey_asm: string; scriptpubkey_type: string; scriptpubkey_address: string; value: number; }; scriptsig: string; scriptsig_asm: string; witness: string[]; is_coinbase: boolean; sequence: number; }[]; vout: { scriptpubkey: string; scriptpubkey_asm: string; scriptpubkey_type: string; scriptpubkey_address: string; value: number; }[]; weight: number; size: number; fee: number; status: { confirmed: boolean; block_height: number; block_hash: string; block_time: number; }; } interface RgbppApis { getRgbppPaymasterInfo(): Promise; getRgbppTransactionHash(btcTxId: string): Promise; getRgbppTransactionState(btcTxId: string): Promise; getRgbppAssetsByBtcTxId(btcTxId: string): Promise; getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise; getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise; getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams): Promise; getRgbppActivityByBtcAddress(btcAddress: string, params?: RgbppApiActivityByAddressParams): Promise; getRgbppSpvProof(btcTxId: string, confirmations: number): Promise; sendRgbppCkbTransaction(payload: RgbppApiSendCkbTransactionPayload): Promise; retryRgbppCkbTransaction(payload: RgbppApiRetryCkbTransactionPayload): Promise; } type RgbppTransactionState = 'completed' | 'failed' | 'delayed' | 'active' | 'waiting'; interface RgbppApiPaymasterInfo { btc_address: string; fee: number; } interface RgbppApiCkbTransactionHash { txhash: string; } interface RgbppApiTransactionStateParams { with_data?: boolean; } interface RgbppApiTransactionState { state: RgbppTransactionState; attempts: number; failedReason?: string; data?: { txid: string; ckbVirtualResult: { ckbRawTx: CKBComponents.RawTransaction; needPaymasterCell: boolean; sumInputsCapacity: string; commitment: string; }; }; } interface RgbppCell extends Cell { typeHash?: Hash; } interface RgbppApiAssetsByAddressParams { type_script?: string; no_cache?: boolean; } interface RgbppApiBalanceByAddressParams { type_script?: string; no_cache?: boolean; } interface RgbppApiBalance { address: string; xudt: RgbppApiXudtBalance[]; } interface RgbppApiXudtBalance { name: string; decimal: number; symbol: string; total_amount: string; available_amount: string; pending_amount: string; type_hash: string; type_script: Script; } interface RgbppApiActivityByAddressParams { rgbpp_only?: boolean; type_script?: string; after_btc_txid?: string; } interface RgbppApiActivity { address: string; cursor: string; txs: { btcTx: BtcApiTransaction; isRgbpp: boolean; isomorphicTx?: { ckbVirtualTx?: CKBComponents.RawTransaction; ckbTx?: CKBComponents.Transaction; inputs?: CKBComponents.CellOutput[]; outputs?: CKBComponents.CellOutput[]; status: { confirmed: boolean; }; }; }[]; } interface RgbppApiSpvProof { proof: string; spv_client: { tx_hash: string; index: string; }; } interface RgbppApiSendCkbTransactionPayload { btc_txid: string; ckb_virtual_result: RgbppApiSendCkbVirtualResult | string; } interface RgbppApiSendCkbVirtualResult { ckbRawTx: CKBComponents.RawTransaction; needPaymasterCell: boolean; sumInputsCapacity: string; commitment: string; } interface RgbppApiRetryCkbTransactionPayload { btc_txid: string; } interface RgbppApiTransactionRetry { success: boolean; state: RgbppTransactionState; } interface RgbppApiXudtAssetInfo { type: string; type_hash: string; type_script: Script; symbol: string; name: string; decimal: number; total_supply?: string; issuer?: string; circulating_supply?: string; token_info_cell_type_hash?: string; } interface RgbppApiSporeAssetInfo { type: string; content_type: string; cluster: { id: string; name: string; description: string; }; } type RgbppApiAssetInfo = RgbppApiXudtAssetInfo | RgbppApiSporeAssetInfo; declare enum ErrorCodes { UNKNOWN = 0, ASSETS_API_RESPONSE_ERROR = 1, ASSETS_API_UNAUTHORIZED = 2, ASSETS_API_INVALID_PARAM = 3, ASSETS_API_RESOURCE_NOT_FOUND = 4, ASSETS_API_RESPONSE_DECODE_ERROR = 5, OFFLINE_DATA_SOURCE_METHOD_NOT_AVAILABLE = 6, OFFLINE_DATA_SOURCE_SPV_PROOF_NOT_FOUND = 7 } declare const ErrorMessages: { 0: string; 2: string; 3: string; 1: string; 4: string; 5: string; 6: string; 7: string; }; declare class BtcAssetsApiError extends Error { code: ErrorCodes; message: string; context?: BtcAssetsApiContext; constructor(payload: { code: ErrorCodes; message?: string; context?: BtcAssetsApiContext; }); static withComment(code: ErrorCodes, comment?: string, context?: BtcAssetsApiContext): BtcAssetsApiError; } declare class OfflineBtcAssetsDataSourceError extends Error { code: ErrorCodes; constructor(errorCode: ErrorCodes, message?: string); } /** * Check if target string is a valid domain. * @exmaple * isDomain('google.com') // => true * isDomain('https://google.com') // => false * isDomain('localhost') // => false * isDomain('localhost', true) // => true */ declare function isDomain(domain: string, allowLocalhost?: boolean): boolean; declare class BtcAssetsApiBase implements BaseApis { url: string; app?: string; domain?: string; origin?: string; private token?; constructor(props: { url: string; app?: string; domain?: string; origin?: string; token?: string; }); request(route: string, options?: BaseApiRequestOptions): Promise; post(route: string, options?: BaseApiRequestOptions): Promise; generateToken(): Promise; init(force?: boolean): Promise; } declare class BtcAssetsApi extends BtcAssetsApiBase implements BtcApis, RgbppApis { /** * Base */ static fromToken(url: string, token: string, origin?: string): BtcAssetsApi; /** * Bitcoin APIs, under the /bitcoin/v1 prefix. */ getBtcBlockchainInfo(): Promise; getBtcBlockByHash(blockHash: string): Promise; getBtcBlockHeaderByHash(blockHash: string): Promise; getBtcBlockHashByHeight(height: number): Promise; getBtcBlockTransactionIdsByHash(blockHash: number): Promise; getBtcRecommendedFeeRates(): Promise; getBtcBalance(address: string, params?: BtcApiBalanceParams): Promise; getBtcUtxos(address: string, params?: BtcApiUtxoParams): Promise; getBtcTransactions(address: string, params?: BtcApiTransactionParams): Promise; getBtcTransaction(txId: string): Promise; sendBtcTransaction(txHex: string): Promise; /** * RGBPP APIs, under the /rgbpp/v1 prefix. */ getRgbppPaymasterInfo(): Promise; getRgbppTransactionHash(btcTxId: string): Promise; getRgbppTransactionState(btcTxId: string, params?: RgbppApiTransactionStateParams): Promise; getRgbppAssetsByBtcTxId(btcTxId: string): Promise; getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise; getRgbppAssetInfoByTypeScript(typeScript: string): Promise; getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise; getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams): Promise; getRgbppActivityByBtcAddress(btcAddress: string, params?: RgbppApiActivityByAddressParams): Promise; getRgbppSpvProof(btcTxId: string, confirmations: number): Promise; sendRgbppCkbTransaction(payload: RgbppApiSendCkbTransactionPayload): Promise; retryRgbppCkbTransaction(payload: RgbppApiRetryCkbTransactionPayload): Promise; } interface OfflineBtcData { txs: BtcApiTransaction[]; utxos: OfflineBtcUtxo[]; rgbppSpvProofs: SpvProofEntry[]; } interface SpvProofEntry { txid: string; confirmations: number; proof: RgbppApiSpvProof; } declare class OfflineBtcAssetsDataSource extends BtcAssetsApi { private txs; private utxos; private rgbppSpvProofs; private defaultFee; constructor(offlineData: OfflineBtcData); private spvKey; getBtcTransaction(txId: string): Promise; getBtcUtxos(address: string, params?: BtcApiUtxoParams): Promise; getBtcRecommendedFeeRates(): Promise; getRgbppSpvProof(btcTxId: string, confirmations: number): Promise; getRgbppPaymasterInfo(): Promise; getBtcBlockchainInfo(): Promise; getBtcBlockByHash(blockHash: string): Promise; getBtcBlockHeaderByHash(blockHash: string): Promise; getBtcBlockHashByHeight(height: number): Promise; getBtcBlockTransactionIdsByHash(blockHash: number): Promise; getBtcBalance(address: string, params?: BtcApiBalanceParams): Promise; getBtcTransactions(address: string, params?: BtcApiTransactionParams): Promise; sendBtcTransaction(txHex: string): Promise; getRgbppTransactionHash(btcTxId: string): Promise; getRgbppTransactionState(btcTxId: string, params?: RgbppApiTransactionStateParams): Promise; getRgbppAssetsByBtcTxId(btcTxId: string): Promise; getRgbppAssetsByBtcUtxo(btcTxId: string, vout: number): Promise; getRgbppAssetInfoByTypeScript(typeScript: string): Promise; getRgbppAssetsByBtcAddress(btcAddress: string, params?: RgbppApiAssetsByAddressParams): Promise; getRgbppBalanceByBtcAddress(btcAddress: string, params?: RgbppApiBalanceByAddressParams): Promise; getRgbppActivityByBtcAddress(btcAddress: string, params?: RgbppApiActivityByAddressParams): Promise; sendRgbppCkbTransaction(payload: RgbppApiSendCkbTransactionPayload): Promise; retryRgbppCkbTransaction(payload: RgbppApiRetryCkbTransactionPayload): Promise; } export { type BaseApiRequestOptions, type BaseApis, type BtcApiBalance, type BtcApiBalanceParams, type BtcApiBlock, type BtcApiBlockHash, type BtcApiBlockHeader, type BtcApiBlockTransactionIds, type BtcApiBlockchainInfo, type BtcApiRecommendedFeeRates, type BtcApiSentTransaction, type BtcApiTransaction, type BtcApiTransactionParams, type BtcApiUtxo, type BtcApiUtxoParams, type BtcApis, BtcAssetsApi, BtcAssetsApiBase, type BtcAssetsApiContext, BtcAssetsApiError, type BtcAssetsApiToken, ErrorCodes, ErrorMessages, type Json, OfflineBtcAssetsDataSource, OfflineBtcAssetsDataSourceError, type OfflineBtcData, type OfflineBtcUtxo, type RgbppApiActivity, type RgbppApiActivityByAddressParams, type RgbppApiAssetInfo, type RgbppApiAssetsByAddressParams, type RgbppApiBalance, type RgbppApiBalanceByAddressParams, type RgbppApiCkbTransactionHash, type RgbppApiPaymasterInfo, type RgbppApiRetryCkbTransactionPayload, type RgbppApiSendCkbTransactionPayload, type RgbppApiSendCkbVirtualResult, type RgbppApiSporeAssetInfo, type RgbppApiSpvProof, type RgbppApiTransactionRetry, type RgbppApiTransactionState, type RgbppApiTransactionStateParams, type RgbppApiXudtAssetInfo, type RgbppApiXudtBalance, type RgbppApis, type RgbppCell, type RgbppTransactionState, type SpvProofEntry, isDomain };