/* tslint:disable */
/* eslint-disable */
/**
 * JavaScript-friendly OutsideExecution V3 structure
 */
export interface JsOutsideExecutionV3 {
    caller: JsFelt;
    execute_after: number;
    execute_before: number;
    calls: JsCall[];
    nonce: [JsFelt, JsFelt];
}

/**
 * Result type for signExecuteFromOutside containing both the OutsideExecution and signature
 */
export interface JsSignedOutsideExecution {
    outside_execution: JsOutsideExecutionV3;
    signature: JsFelt[];
}

export type JsFeeSource = "PAYMASTER" | "CREDITS";

export type Felts = JsFelt[];

export type JsFelt = Felt;

export interface JsCall {
    contractAddress: JsFelt;
    entrypoint: string;
    calldata: JsFelt[];
}

export interface Owner {
    signer?: Signer;
    account?: JsFelt;
}

export interface CallPolicy {
    target: JsFelt;
    method: JsFelt;
    authorized?: boolean;
}

export interface TypedDataPolicy {
    scope_hash: JsFelt;
    authorized?: boolean;
}

export interface ApprovalPolicy {
    target: JsFelt;
    spender: JsFelt;
    amount: JsFelt;
}

export type Policy = CallPolicy | TypedDataPolicy | ApprovalPolicy;

export type JsAddSignerInput = SignerInput;

export interface WebauthnSigner {
    rpId: string;
    credentialId: string;
    publicKey: string;
}

export interface Signer {
    webauthns?: WebauthnSigner[];
    webauthn?: WebauthnSigner;
    starknet?: StarknetSigner;
    eip191?: Eip191Signer;
}

export type JsRemoveSignerInput = SignerInput;

export interface StarknetSigner {
    privateKey: JsFelt;
}

export interface Eip191Signer {
    address: string;
}

export type JsRevokableSession = RevokableSession;

export interface Session {
    policies: Policy[];
    expiresAt: number;
    metadataHash: JsFelt;
    sessionKeyGuid: JsFelt;
    guardianKeyGuid: JsFelt;
}

export interface Credentials {
    authorization: JsFelt[];
    privateKey: JsFelt;
}

export type JsSubscribeSessionResult = SubscribeCreateSessionSubscribeCreateSession;

export interface AuthorizedSession {
    session: Session;
    authorization: JsFelt[] | null;
    isRegistered: boolean;
    expiresAt: number;
    allowedPoliciesRoot: JsFelt;
    metadataHash: JsFelt;
    sessionKeyGuid: JsFelt;
    guardianKeyGuid: JsFelt;
}

export interface JsFeeEstimate {
    l1_gas_consumed: number;
    l1_gas_price: number;
    l2_gas_consumed: number;
    l2_gas_price: number;
    l1_data_gas_consumed: number;
    l1_data_gas_price: number;
    overall_fee: number;
}

export type JsPriceUnit = "WEI" | "FRI";

export interface JsEstimateFeeDetails {
    nonce: JsFelt;
}

export type JsRegister = RegisterInput;

export type JsRegisterResponse = ResponseData;


export class CartridgeAccount {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  disconnect(): Promise<void>;
  deploySelf(max_fee?: JsFeeEstimate | null): Promise<any>;
  static fromStorage(cartridge_api_url: string): Promise<CartridgeAccountWithMeta | undefined>;
  /**
   * Creates a new `CartridgeAccount` instance with a randomly generated Starknet signer.
   * The controller address is computed internally based on the generated signer.
   *
   * # Parameters
   * - `rpc_url`: The URL of the JSON-RPC endpoint.
   * - `username`: Username associated with the account.
   */
  static newHeadless(class_hash: JsFelt, rpc_url: string, username: string, cartridge_api_url: string): Promise<CartridgeAccountWithMeta>;
  removeOwner(signer: JsRemoveSignerInput): Promise<void>;
  signMessage(typed_data: string): Promise<Felts>;
  skipSession(app_id: string, policies: Policy[]): Promise<void>;
  createSession(app_id: string, policies: Policy[], expires_at: bigint, authorize_user_execution?: boolean | null): Promise<AuthorizedSession | undefined>;
  revokeSession(session: JsRevokableSession): Promise<void>;
  revokeSessions(sessions: JsRevokableSession[]): Promise<void>;
  delegateAccount(): Promise<JsFelt>;
  registerSession(app_id: string, policies: Policy[], expires_at: bigint, public_key: JsFelt, max_fee?: JsFeeEstimate | null): Promise<any>;
  estimateInvokeFee(calls: JsCall[]): Promise<JsFeeEstimate>;
  trySessionExecute(app_id: string, calls: JsCall[], fee_source?: JsFeeSource | null): Promise<any>;
  createPasskeySigner(rp_id: string): Promise<JsAddSignerInput>;
  hasRequestedSession(app_id: string, policies: Policy[]): Promise<boolean>;
  executeFromOutsideV2(calls: JsCall[], fee_source?: JsFeeSource | null): Promise<any>;
  executeFromOutsideV3(calls: JsCall[], fee_source?: JsFeeSource | null): Promise<any>;
  /**
   * Checks if there are stored policies for a given app_id.
   *
   * # Parameters
   * - `app_id`: The application identifier to check for stored policies
   *
   * # Returns
   * `true` if policies exist for the given app_id, `false` otherwise
   */
  hasPoliciesForAppId(app_id: string): Promise<boolean>;
  registerSessionCalldata(policies: Policy[], expires_at: bigint, public_key: JsFelt): Promise<any>;
  /**
   * Signs an OutsideExecution V3 transaction and returns both the OutsideExecution object and its signature.
   *
   * # Parameters
   * - `calls`: Array of calls to execute from outside
   *
   * # Returns
   * A `JsSignedOutsideExecution` containing the OutsideExecution V3 object and its signature
   */
  signExecuteFromOutside(calls: JsCall[]): Promise<JsSignedOutsideExecution>;
  isRegisteredSessionAuthorized(policies: Policy[], public_key?: JsFelt | null): Promise<AuthorizedSession | undefined>;
  hasAuthorizedPoliciesForCalls(app_id: string, calls: JsCall[]): Promise<boolean>;
  hasAuthorizedPoliciesForMessage(app_id: string, typed_data: string): Promise<boolean>;
  /**
   * Creates a new `CartridgeAccount` instance.
   *
   * # Parameters
   * - `rpc_url`: The URL of the JSON-RPC endpoint.
   * - `address`: The blockchain address associated with the account.
   * - `username`: Username associated with the account.
   * - `owner`: A Owner struct containing the owner signer and associated data.
   */
  static new(class_hash: JsFelt, rpc_url: string, address: JsFelt, username: string, owner: Owner, cartridge_api_url: string): Promise<CartridgeAccountWithMeta>;
  execute(calls: JsCall[], max_fee?: JsFeeEstimate | null, fee_source?: JsFeeSource | null): Promise<any>;
  upgrade(new_class_hash: JsFelt): Promise<JsCall>;
  register(register: JsRegister): Promise<JsRegisterResponse>;
  addOwner(owner?: Signer | null, signer_input?: JsAddSignerInput | null, rp_id?: string | null): Promise<void>;
  getNonce(): Promise<any>;
}

export class CartridgeAccountMeta {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  classHash(): string;
  ownerGuid(): JsFelt;
  owner(): Owner;
  address(): string;
  rpcUrl(): string;
  chainId(): string;
  username(): string;
}

export class CartridgeAccountWithMeta {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  intoAccount(): CartridgeAccount;
  meta(): CartridgeAccountMeta;
}

export class ControllerFactory {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  static fromStorage(cartridge_api_url: string): Promise<CartridgeAccountWithMeta | undefined>;
  /**
   * Login to an existing controller account.
   *
   * # Parameters
   *
   * * `create_wildcard_session` - Whether to create a wildcard session on login. Defaults to `true`
   *   for backward compatibility. Set to `false` when using the `register_session` flow where
   *   specific policies will be registered instead of using a wildcard session.
   *
   * # Returns
   *
   * Returns a `LoginResult` containing:
   * * `account` - The controller account
   * * `session` - Optional session (Some if `create_wildcard_session` is true, None otherwise)
   *
   * # Testing
   *
   * The core logic is tested in the SDK layer:
   * * `account_sdk::tests::session_test::test_wildcard_session_creation` - Tests session creation
   * * `account_sdk::tests::session_test::test_login_with_wildcard_session_and_execute` - Tests login with session + execution
   * * `account_sdk::tests::session_test::test_login_without_session_can_still_execute` - Tests login without session + execution
   *
   * The WASM layer is a thin wrapper that:
   * 1. Converts WASM types to SDK types
   * 2. Calls `Controller::new` and optionally `create_wildcard_session`
   * 3. Handles WebAuthn signer updates when multiple signers are present
   * 4. Registers the session with Cartridge API if requested
   */
  static login(username: string, class_hash: JsFelt, rpc_url: string, address: JsFelt, owner: Owner, cartridge_api_url: string, session_expires_at_s: bigint, is_controller_registered?: boolean | null, create_wildcard_session?: boolean | null, app_id?: string | null): Promise<LoginResult>;
  /**
   * This should only be used with webauthn signers
   */
  static apiLogin(username: string, class_hash: JsFelt, rpc_url: string, address: JsFelt, owner: Owner, cartridge_api_url: string): Promise<CartridgeAccountWithMeta>;
}

export enum ErrorCode {
  StarknetFailedToReceiveTransaction = 1,
  StarknetContractNotFound = 20,
  StarknetBlockNotFound = 24,
  StarknetInvalidTransactionIndex = 27,
  StarknetClassHashNotFound = 28,
  StarknetTransactionHashNotFound = 29,
  StarknetPageSizeTooBig = 31,
  StarknetNoBlocks = 32,
  StarknetInvalidContinuationToken = 33,
  StarknetTooManyKeysInFilter = 34,
  StarknetContractError = 40,
  StarknetTransactionExecutionError = 41,
  StarknetClassAlreadyDeclared = 51,
  StarknetInvalidTransactionNonce = 52,
  StarknetInsufficientMaxFee = 53,
  StarknetInsufficientAccountBalance = 54,
  StarknetValidationFailure = 55,
  StarknetCompilationFailed = 56,
  StarknetContractClassSizeIsTooLarge = 57,
  StarknetNonAccount = 58,
  StarknetDuplicateTx = 59,
  StarknetCompiledClassHashMismatch = 60,
  StarknetUnsupportedTxVersion = 61,
  StarknetUnsupportedContractClassVersion = 62,
  StarknetUnexpectedError = 63,
  StarknetNoTraceAvailable = 10,
  StarknetReplacementTransactionUnderpriced = 64,
  StarknetFeeBelowMinimum = 65,
  SignError = 101,
  StorageError = 102,
  AccountFactoryError = 103,
  PaymasterExecutionTimeNotReached = 104,
  PaymasterExecutionTimePassed = 105,
  PaymasterInvalidCaller = 106,
  PaymasterRateLimitExceeded = 107,
  PaymasterNotSupported = 108,
  PaymasterHttp = 109,
  PaymasterExcecution = 110,
  PaymasterSerialization = 111,
  CartridgeControllerNotDeployed = 112,
  InsufficientBalance = 113,
  OriginError = 114,
  EncodingError = 115,
  SerdeWasmBindgenError = 116,
  CairoSerdeError = 117,
  CairoShortStringToFeltError = 118,
  DeviceCreateCredential = 119,
  DeviceGetAssertion = 120,
  DeviceBadAssertion = 121,
  DeviceChannel = 122,
  DeviceOrigin = 123,
  AccountSigning = 124,
  AccountProvider = 125,
  AccountClassHashCalculation = 126,
  AccountFeeOutOfRange = 128,
  ProviderRateLimited = 129,
  ProviderArrayLengthMismatch = 130,
  ProviderOther = 131,
  SessionAlreadyRegistered = 132,
  UrlParseError = 133,
  Base64DecodeError = 134,
  CoseError = 135,
  PolicyChainIdMismatch = 136,
  InvalidOwner = 137,
  GasPriceTooHigh = 138,
  TransactionTimeout = 139,
  ConversionError = 140,
  InvalidChainId = 141,
  SessionRefreshRequired = 142,
  ManualExecutionRequired = 143,
  ForbiddenEntrypoint = 144,
  GasAmountTooHigh = 145,
  ApproveExecutionRequired = 146,
}

export class JsChainConfig {
  free(): void;
  [Symbol.dispose](): void;
  constructor(class_hash: JsFelt, rpc_url: string, owner: Owner, address?: JsFelt | null);
  readonly class_hash: JsFelt;
  readonly owner: Owner;
  readonly address: JsFelt | undefined;
  readonly rpc_url: string;
}

export class JsControllerError {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  code: ErrorCode;
  message: string;
  get data(): string | undefined;
  set data(value: string | null | undefined);
}

export class LoginResult {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  intoValues(): Array<any>;
}

export class MultiChainAccount {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  /**
   * Gets an account instance for a specific chain
   */
  controller(chain_id: JsFelt): Promise<CartridgeAccount>;
  /**
   * Loads a MultiChainAccount from storage
   */
  static fromStorage(cartridge_api_url: string): Promise<MultiChainAccount | undefined>;
  /**
   * Removes a chain configuration
   */
  removeChain(chain_id: JsFelt): Promise<void>;
  /**
   * Creates a new MultiChainAccount with multiple chain configurations
   */
  static create(username: string, chain_configs: JsChainConfig[], cartridge_api_url: string): Promise<MultiChainAccount>;
  /**
   * Adds a new chain configuration
   */
  addChain(config: JsChainConfig): Promise<void>;
}

export class MultiChainAccountMeta {
  private constructor();
  free(): void;
  [Symbol.dispose](): void;
  readonly chains: JsFelt[];
  readonly username: string;
}

/**
 * Computes the Starknet contract address for a controller account without needing a full instance.
 *
 * # Arguments
 *
 * * `class_hash` - The class hash of the account contract (JsFelt).
 * * `owner` - The owner configuration for the account.
 * * `salt` - The salt used for address calculation (JsFelt).
 *
 * # Returns
 *
 * The computed Starknet contract address as a `JsFelt`.
 */
export function computeAccountAddress(class_hash: JsFelt, owner: Owner, salt: JsFelt): JsFelt;

export function signerToGuid(signer: Signer): JsFelt;

/**
 * Subscribes to the creation of a session for a given controller, session_key_guid and cartridge api url.
 * The goal of this function is to know from any place when the register session flow has been completed, and to
 * get the authorization.
 */
export function subscribeCreateSession(session_key_guid: JsFelt, cartridge_api_url: string): Promise<JsSubscribeSessionResult>;
