import Client from '../api_client/client'; import { KwilConfig } from '../api_client/config'; import { GenericResponse } from '../core/resreq'; import { Database, DeployBody, DropBody } from '../core/database'; import { TxReceipt } from '../core/tx'; import { Account, ChainInfo, ChainInfoOpts, DatasetInfo } from '../core/network'; import { TxInfoReceipt } from '../core/txQuery'; import { EnvironmentType } from '../core/enums'; import { ActionBody, CallBody } from '../core/action'; import { KwilSigner } from '../core/kwilSigner'; import { Funder } from '../funder/funder'; import { Auth } from '../auth/auth'; import { MsgReceipt } from '../core/message'; import { QueryParams } from '../utils/types'; /** * The main class for interacting with the Kwil network. */ export declare abstract class Kwil extends Client { protected readonly chainId: string; private readonly autoAuthenticate; funder: Funder; auth: Auth; private authMode?; protected constructor(opts: KwilConfig); /** * Retrieves the actions in a database given its namespace. * * @param namespace - The namespace of the actions to retrieve. * @returns A promise that resolves to the actions in the database. */ getActions(namespace: string): Promise>; /** * Retrieves an account using the owner's Ethereum wallet address. * * @param owner - The owner's identifier (e.g. Ethereum wallet address or ED25119 keys). Ethereum addresses and ED25519 public keys can be passed as a hex string (0x123...) or as bytes (Uint8Array). * @returns A promise that resolves to an Account object. The account object includes the account's id, balance, and nonce. */ getAccount(owner: string | Uint8Array, keyType?: string): Promise>; /** * Executes a transaction on a Kwil network. These are mutative actions that must be mined on the Kwil network's blockchain. * * @param actionBody - The body of the action to send. This should use the `ActionBody` interface. * @param kwilSigner - The signer for the action transactions. * @param synchronous - (optional) If true, the broadcast will wait for the transaction to be mined before returning. If false, the broadcast will return the transaction hash immediately, regardless of if the transaction is successful. Defaults to false. * @returns A promise that resolves to the receipt of the transaction. */ execute(actionBody: ActionBody, kwilSigner: KwilSigner, synchronous?: boolean): Promise>; /** * Performs a read-only SELECT query on a database. * This operation does not modify state. * * @param query - The SELECT query to execute * @param params - Optional array of parameters to bind to the query ($1, $2, etc.) * @returns Promise resolving to query results */ selectQuery(query: string, params?: QueryParams): Promise>; /** * @deprecated Use selectQuery(query, params?) instead. This method will be removed in next major version. */ selectQuery(dbid: string, query: string): Promise>; private legacySelectQuery; /** * Executes a mutative SQL query (INSERT, UPDATE, DELETE) on a database. * * @param query - The SQL query to execute, including the database identifier in curly braces. * Use parameterized queries with @paramName placeholders for better security (recommended): * '{dbname}INSERT INTO users (name) VALUES (@name)' * * Raw queries are possible but discouraged: * '{dbname}INSERT INTO users (name) VALUES ('john')' * * @param params - Object containing named parameters to bind to the query. Parameters are referenced * using @paramName syntax in the query. * @param kwilSigner - Required signer for executing mutative queries * @param synchronous - (optional) If true, waits for transaction to be mined * * @example * // Insert with parameters * await kwil.execSql( * '{mydb}INSERT INTO users (name, email) VALUES ($name, $email)', * { $name: 'John', $email: 'john@example.com' }, * signer * ); * * // Update with parameters * await kwil.execSql( * '{mydb}UPDATE users SET status = $status WHERE id = $id', * { $status: 'active', $id: 123 }, * signer * ); * * // Delete with parameters * await kwil.execSql( * '{mydb}DELETE FROM users WHERE id = $id', * { $id: 123 }, * signer * ); * * @returns Promise resolving to transaction receipt */ execSql(query: string, params: QueryParams, signer: KwilSigner, synchronous?: boolean): Promise>; /** * Retrieves information about a transaction given its hash. * * @param hash - The `tx_hash` of the transaction. * @returns A promise that resolves to the transaction info receipt. */ txInfo(hash: string): Promise>; /** * Retrieves the chain id, block height, and latest block hash of the configured network. * * Will log a warning if the returned chain id does not match the configured chain id. * * @param {ChainInfoOpts} opts - Options for the chain info request. * @returns {ChainInfo} - A promise that resolves to the chain info. */ chainInfo(opts?: ChainInfoOpts): Promise>; /** * Pings the server and gets a response. * * @returns A promise that resolves to a string indicating the server's response. */ ping(): Promise>; /** * Generates a unique database identifier (DBID) from the provided owner's identifier (e.g. wallet address, public key, etc.) and a database name. * * @param owner - The owner's identifier (e.g wallet address, public key, etc.). Ethereum addresses can be passed as a hex string (0x123...) or as bytes (Uint8Array). NEAR protocol public keys can be passed as the base58 encoded public key (with "ed25519:" prefix), a hex string, or bytes (Uint8Array). * @param name - The name of the database. This should be a unique name to identify the database. * @deprecated DBID's are no longer in use. This method will be removed in the next major version. * @returns A string that represents the unique identifier for the database. */ getDBID(owner: string | Uint8Array, name: string): string; /** * Retrieves the schema of a database given its unique identifier (DBID). * * @param dbid - The unique identifier of the database. The DBID can be generated using the kwil.getDBID method. * @deprecated Use `kwil.selectQuery(query, params?)` instead. This method will be removed in the next major version. * @returns A promise that resolves to the schema of the database. */ getSchema(dbid: string): Promise>; /** * Deploys a database to the Kwil network. * * @param deployBody - The body of the database to deploy. This should use the `DeployBody` interface. * @param kwilSigner - The signer for the database deployment. * @param synchronous - (optional) If true, the broadcast will wait for the transaction to be mined before returning. If false, the broadcast will return the transaction hash immediately, regardless of if the transaction is successful. Defaults to false. * @deprecated Use `kwil.execSql()` instead. This method will be removed in the next major version. * @returns A promise that resolves to the receipt of the transaction. */ deploy(deployBody: DeployBody, kwilSigner: KwilSigner, synchronous?: boolean): Promise>; /** * Drops a database from the Kwil network. * * @param dropBody - The body of the database to drop. This should use the `DropBody` interface. * @param kwilSigner - The signer for the database drop. * @param synchronous - (optional) If true, the broadcast will wait for the transaction to be mined before returning. If false, the broadcast will return the transaction hash immediately, regardless of if the transaction is successful. Defaults to false. * @deprecated Use `kwil.execSql()` instead. This method will be removed in the next major version. * @returns A promise that resolves to the receipt of the transaction. */ drop(dropBody: DropBody, kwilSigner: KwilSigner, synchronous?: boolean): Promise>; /** * Lists all databases owned by a particular owner. * * @param owner (optional) - Lists the databases on a network. Can pass and owner identifier to see all the databases deployed by a specific account, or leave empty to see al the databases deployed on the network. The owner's public key (Ethereum or NEAR Protocol). Ethereum keys can be passed as a hex string (0x123...) or as bytes (Uint8Array). * @deprecated Use `kwil.selectQuery(query, params?)` instead. This method will be removed in the next major version. * @returns A promise that resolves to a list of database names. */ listDatabases(owner?: string | Uint8Array): Promise>; /** * Calls a Kwil node. This can be used to execute read-only ('view') actions on Kwil. * * @param {CallBody} callBody - The message to send. The message can be built using the buildMsg() method in the Action class. * @param {KwilSigner} kwilSigner (optional) - KwilSigner should be passed if the action requires authentication OR if the action uses a `@caller` contextual variable. If `@caller` is used and authentication is not required, the user will not be prompted to authenticate; however, the user's identifier will be passed as the sender. * @param {(...args: any) => void} cookieHandlerCallback (optional) - the callback to handle the cookie if in the NODE environment * @returns A promise that resolves to the receipt of the message. */ protected baseCall(callBody: CallBody, kwilSigner?: KwilSigner, cookieHandlerCallback?: { setCookie: () => void; resetCookie: () => void; }): Promise>>; /** * Check if authMode is already set, if not call healthModeCheckClient() * healthModeCheckClient => RPC call to retrieve health of blockchain and kwild mode (PRIVATE or OPEN (PUBLIC)) * */ private ensureAuthenticationMode; /** * Builds a message with a chainId, namespace, name, and description of the action. * NOT INCLUDED => challenge, sender, signature * * @param callBody - The message to send. The message can be built using the buildMsg() method in the Action class. * @param kwilSigner (optional) - KwilSigner should be passed if the action requires authentication OR if the action uses a `@caller` contextual variable. If `@caller` is used and authentication is not required, the user will not be prompted to authenticate; however, the user's identifier will be passed as the sender. * @param challenge (optional) - To ensure a challenge is passed into the message before the signer in PRIVATE mode * @param signature (optional) - To ensure a signature is passed into the message before the signer in PRIVATE mode * @returns A message object that can be sent to the Kwil network. * @throws — Will throw an error if the action is being built or if there's an issue with the schema or account retrieval. * @throws — Will throw an error if the action is not a view action. */ private buildMessage; /** * Adds a signer to the message * * @param msgBuilder - The Action class that handles the building of the message * @param kwilSigner - KwilSigner should be passed if the action requires authentication OR if the action uses a `@caller` contextual variable. If `@caller` is used and authentication is not required, the user will not be prompted to authenticate; however, the user's identifier will be passed as the sender. * @returns the Action class responsible for building the view action message with the sender attached * */ private addSignerToMessage; /** * Checks authentication errors for PRIVATE mode * Signs message and then retries request for successful response * * @param {CallBodyNode} actionBody - The message to send. The message can be built using the buildMsg() method in the Action class. * @param {KwilSigner} kwilSigner (optional) - KwilSigner should be passed if the action requires authentication OR if the action uses a `@caller` contextual variable. If `@caller` is used and authentication is not required, the user will not be prompted to authenticate; however, the user's identifier will be passed as the sender. * @returns the authentication body that consists of the challenge and signature required for PRIVATE mode */ private handleAuthenticatePrivate; }