import { CompilationData, InputTemplate, CompilerBCH, OutputTemplate, WalletTemplate, Output, Input, TransactionCommon } from '@bitauth/libauth';
import Client from '@walletconnect/sign-client';
import { ProposalTypes, SessionTypes, SignClientTypes, PairingTypes } from '@walletconnect/types';
import EventEmitter from 'events';
import Client$1, { WalletKitTypes } from '@reown/walletkit';
import WalletConnectCore from '@walletconnect/core';

type Promisable<T> = Promise<T> | T;

type CompilationDataBCH = CompilationData<never>;
type InputTemplateBCH = InputTemplate<CompilerBCH, false, CompilationDataBCH>;
type OutputTemplateBCH = OutputTemplate<CompilerBCH, false, CompilationDataBCH>;
interface ChangeTemplate {
    template: WalletTemplate;
    data: CompilationDataBCH;
}
interface SourceOutputs {
    [outpointId: string]: Output;
}
type Unspent = Input<{
    template: WalletTemplate;
    data: CompilationDataBCH;
    script: string;
    valueSatoshis: bigint;
    token?: {
        amount: bigint;
        category: Uint8Array;
        nft?: {
            capability: 'none' | 'mutable' | 'minting';
            commitment: Uint8Array;
        };
    };
}> & {
    lockingBytecode: Uint8Array;
};
interface NetworkCallbacks {
    getSourceOutput: (outpointTransactionHash: Uint8Array, outpointIndex: number) => Promise<Output>;
}
interface Scope {
    template?: WalletTemplate;
    allowedTokens?: Array<string>;
}
interface WalletCallbacks {
    getChangeTemplate: () => Promisable<ChangeTemplate>;
    getUnspents: () => Promisable<Array<Unspent>>;
}
interface CashRPCV0Opts {
    network: NetworkCallbacks;
    scope?: Scope;
    signerKey?: Uint8Array;
    wallet?: WalletCallbacks;
}
interface RpcRequestResponse {
    request: {
        method: string;
        params?: unknown;
    };
    response: unknown;
}
interface GetBalanceV0 extends RpcRequestResponse {
    request: {
        method: 'bch_getBalance_V0';
    };
    response: {
        [categoryId: string]: bigint;
    };
}
interface GetChangeLockingBytecodeV0 extends RpcRequestResponse {
    request: {
        method: 'bch_getChangeLockingBytecode_V0';
    };
    response: Uint8Array;
}
interface GetTokensV0 extends RpcRequestResponse {
    request: {
        method: 'bch_getTokens_V0';
    };
    response: Array<{
        outpointTransactionHash: Uint8Array;
        outpointIndex: number;
        token: {
            category: Uint8Array;
            amount: bigint;
            nft?: {
                commitment: Uint8Array;
                capability: 'none' | 'mutable' | 'minting';
            };
        };
    }>;
}
interface SignMessageV0 extends RpcRequestResponse {
    request: {
        method: 'bch_signMessage_V0';
        params: {
            message: Uint8Array;
        };
    };
    response: Uint8Array;
}
interface SignTransactionV0Data {
    [identifier: string]: Uint8Array;
}
interface SignTransactionV0InputWalletScoped {
    outpointTransactionHash: Uint8Array;
    outpointIndex: number;
}
interface SignTransactionV0InputTemplateScoped {
    outpointTransactionHash: Uint8Array;
    outpointIndex: number;
    script: string;
    data?: SignTransactionV0Data;
}
interface SignTransactionV0OutputWalletScoped {
    valueSatoshis: bigint;
    token?: Output['token'];
}
interface SignTransactionV0OutputTemplateScoped {
    script: string;
    valueSatoshis: bigint;
    token?: Output['token'];
    data?: SignTransactionV0Data;
}
interface SignTransactionV0Params {
    transaction: {
        version?: number;
        locktime?: number;
        inputs?: Array<SignTransactionV0InputTemplateScoped | SignTransactionV0InputWalletScoped>;
        outputs?: Array<SignTransactionV0OutputTemplateScoped | SignTransactionV0OutputWalletScoped>;
    };
    signerKey?: string;
    userPrompt?: string;
    validate?: boolean;
}
interface SignTransactionV0Response {
    transactionHash: Uint8Array;
    transaction: TransactionCommon<Input, Output & {
        resolvedVariables?: {
            [identifier: string]: Uint8Array;
        };
    }>;
    sourceOutputs: Output<Uint8Array, Uint8Array>[];
}
interface SignTransactionV0 extends RpcRequestResponse {
    request: {
        method: 'bch_signTransaction_V0';
        params: Array<SignTransactionV0Params>;
    };
    response: Array<SignTransactionV0Response>;
}
declare class CashRPCError extends Error {
    readonly stackTrace?: string | undefined;
    constructor(message: string, stackTrace?: string | undefined);
}

declare const SupportedChains: string[];
declare const SupportedMethods: string[];
declare const SupportedEvents: string[];
interface BchNamespace extends ProposalTypes.BaseRequiredNamespace {
    protocol: 'CashRPC:0';
    template: WalletTemplate;
    allowedTokens: Array<string>;
}
interface BchSession extends Omit<SessionTypes.Struct, 'requiredNamespaces'> {
    requiredNamespaces: {
        bch: BchNamespace;
    };
}
type BchSessionProposal = WalletKitTypes.SessionProposal & {
    params: BchSession;
};
interface WalletProperties {
    autoApprove: Array<string>;
}
type RequestEvent = WalletKitTypes.BaseEventArgs<{
    request: {
        method: string;
        /** Params as Extended JSON (i.e. LibAuth's stringify() function) */
        params: string;
    };
}>;
interface EventCallbacks {
    onSessionsUpdated: (sessions: Record<string, BchSession>) => Promisable<void>;
    onSessionProposal: (proposalEvent: BchSessionProposal) => Promisable<WalletProperties>;
    onSessionDelete: () => Promisable<void>;
    onRPCRequest: (session: BchSession, request: RpcRequestResponse['request'], response: RpcRequestResponse['response']) => Promisable<void>;
    onError: (error: Error) => Promisable<void>;
}
interface CacaoPayload {
    aud: string;
    domain: string;
    chainId: string;
    type: 'cashconnect';
    nonce: string;
    iat: string;
}
interface AuthRequestV0 extends RpcRequestResponse {
    method: 'wc_authRequest';
    params: {
        cacaoPayload: CacaoPayload;
    };
    response: Uint8Array;
}
interface CacaoAuth {
    cacaoPayload: CacaoPayload;
    publicKey: Uint8Array;
    signature: Uint8Array;
}

interface RequestOpts {
    hide?: true;
    message?: string;
}
type DialogCallback = () => void;
declare class BaseNewSessionDialog {
    readonly url: string;
    readonly cancelCallback: DialogCallback;
    constructor(url: string, cancelCallback: DialogCallback);
    cancel(): void;
    close(): void;
}
declare class BaseReconnectSessionDialog {
    readonly cancelCallback: DialogCallback;
    readonly newSessionCallback: DialogCallback;
    constructor(cancelCallback: DialogCallback, newSessionCallback: DialogCallback);
    cancel(): void;
    newConnection(): void;
    close(): void;
}
declare class BaseRequestDialog {
    opts: RequestOpts;
    cancelCallback: DialogCallback;
    constructor(opts: RequestOpts, cancelCallback: DialogCallback);
    cancel(): void;
    close(): void;
}
interface DappDialogs {
    newSession: typeof BaseNewSessionDialog;
    reconnectSession: typeof BaseReconnectSessionDialog;
    request: typeof BaseRequestDialog;
}
declare class CashConnectDapp extends EventEmitter {
    readonly options: SignClientTypes.Options;
    readonly chain: string;
    readonly dialogs: DappDialogs;
    client: Client;
    session?: SessionTypes.Struct;
    onConnected?: (session: SessionTypes.Struct) => Promise<void>;
    constructor(options: SignClientTypes.Options, chain: string, dialogs: DappDialogs);
    start(): Promise<void>;
    connect(requiredNamespaces: ProposalTypes.RequiredNamespaces): Promise<boolean>;
    newSession(requiredNamespaces: ProposalTypes.RequiredNamespaces): Promise<"CONNECTED" | "CANCELLED">;
    reconnectSession(requiredNamespaces: ProposalTypes.RequiredNamespaces): Promise<'CONNECTED' | 'CANCELLED' | 'NEW_SESSION'>;
    disconnect(): Promise<void>;
    request<T extends RpcRequestResponse>(method: T['request']['method'], params?: T['request']['params'], opts?: RequestOpts): Promise<T['response']>;
    authRequest(opts: RequestOpts): Promise<CacaoAuth>;
    disconnectInactiveSessions(): Promise<void>;
    onSessionDisconnect(): Promise<void>;
    onSessionUpdate(): Promise<void>;
    onSessionEvent(event: any): Promise<void>;
}

declare class CashRPC_V0 {
    readonly opts: CashRPCV0Opts;
    readonly template?: WalletTemplate;
    readonly templateCompiler?: CompilerBCH;
    constructor(opts: CashRPCV0Opts);
    getBalance(): Promise<GetBalanceV0['response']>;
    getChangeLockingBytecode(): Promise<GetChangeLockingBytecodeV0['response']>;
    getTokens(): Promise<GetTokensV0['response']>;
    signMessage(params: SignMessageV0['request']['params']): Promise<SignMessageV0['response']>;
    signTransaction(params: SignTransactionV0['request']['params']): Promise<SignTransactionV0['response']>;
    provideData(signerKey?: string, data?: SignTransactionV0Data): Promise<CompilationDataBCH>;
    parseProvidedInputs(inputs: Array<SignTransactionV0InputTemplateScoped | SignTransactionV0InputWalletScoped>, unspents: Array<Unspent>, localSourceOutputs: SourceOutputs, signerKey?: string): Promise<Array<InputTemplateBCH>>;
    parseProvidedOutputs(outputs: Array<SignTransactionV0OutputTemplateScoped | SignTransactionV0OutputWalletScoped>, signerKey?: string): Promise<Array<OutputTemplateBCH>>;
    getSourceOutput(outpointTransactionHash: Uint8Array, outpointIndex: number, localSourceOutputs: SourceOutputs): Promise<Output>;
    doesUnspentContainAllowedToken(unspent: Unspent): boolean;
    doesPayloadLookMalicious(payload: Uint8Array): boolean;
}

declare class CashConnectWallet {
    readonly privateKey: Uint8Array;
    readonly projectId: string;
    readonly metadata: WalletKitTypes.Metadata;
    readonly eventCallbacks: EventCallbacks;
    readonly cashRpcOpts: Required<Pick<CashRPCV0Opts, 'wallet' | 'network'>>;
    core: WalletConnectCore;
    web3Wallet: Client$1;
    private sessionProposalHandler;
    private sessionDeleteHandler;
    private sessionRequestHandler;
    constructor(privateKey: Uint8Array, projectId: string, metadata: WalletKitTypes.Metadata, eventCallbacks: EventCallbacks, cashRpcOpts: Required<Pick<CashRPCV0Opts, 'wallet' | 'network'>>);
    start(): Promise<void>;
    stop(): Promise<void>;
    pair(url: string): Promise<PairingTypes.Struct>;
    getActiveSessions(): Record<string, BchSession>;
    disconnectSession(topic: string): Promise<void>;
    disconnectAllSessions(): Promise<void>;
    walletStateHasChanged(chainId?: string): Promise<void>;
    onSessionProposal(proposalEvent: BchSessionProposal): Promise<void>;
    onSessionDelete(deleteEvent: Omit<WalletKitTypes.BaseEventArgs, 'params'>): Promise<void>;
    onSessionRequest(requestEvent: RequestEvent): Promise<void>;
    private cashRpcFromSession;
    static checkMethodIsAllowed(session: BchSession, method: string): void;
    static deleteAccount(privateKey: Uint8Array): Promise<void>;
}

export { type AuthRequestV0, BaseNewSessionDialog, BaseReconnectSessionDialog, BaseRequestDialog, type BchNamespace, type BchSession, type BchSessionProposal, type CacaoAuth, type CacaoPayload, CashConnectDapp, CashConnectWallet, CashRPCError, type CashRPCV0Opts, CashRPC_V0, type ChangeTemplate, type CompilationDataBCH, type DappDialogs, type DialogCallback, type EventCallbacks, type GetBalanceV0, type GetChangeLockingBytecodeV0, type GetTokensV0, type InputTemplateBCH, type NetworkCallbacks, type OutputTemplateBCH, type RequestEvent, type RequestOpts, type RpcRequestResponse, type Scope, type SignMessageV0, type SignTransactionV0, type SignTransactionV0Data, type SignTransactionV0InputTemplateScoped, type SignTransactionV0InputWalletScoped, type SignTransactionV0OutputTemplateScoped, type SignTransactionV0OutputWalletScoped, type SignTransactionV0Params, type SignTransactionV0Response, type SourceOutputs, SupportedChains, SupportedEvents, SupportedMethods, type Unspent, type WalletCallbacks, type WalletProperties };
