UNPKG

@custonomy/ton-js-bridge

Version:

TON Connect JS Bridge for Custonomy

93 lines (92 loc) 2.81 kB
import { AppRequest, ConnectEvent, ConnectRequest, DeviceInfo, WalletEvent, WalletResponse, RpcMethod } from "@tonconnect/protocol"; export interface WalletInfo { name: string; image: string; tondns?: string; about_url: string; } export declare enum WEB3ASY_MODE { BACKEND = "backend", WIDGET = "widget", NOWIDGET = "nowidget" } export interface TonConnectBridge { deviceInfo: DeviceInfo; walletInfo?: WalletInfo; protocolVersion: number; isWalletBrowser: boolean; connect(protocolVersion: number, message: ConnectRequest): Promise<ConnectEvent>; restoreConnection(): Promise<ConnectEvent>; send<T extends RpcMethod>(message: AppRequest<T>): Promise<WalletResponse<T>>; listen(callback: (event: WalletEvent) => void): () => void; } export declare enum WEB3ASY_NETWORK { TON_MAINNET = "-239", TON_TESTNET = "-3" } export type TCallback = (...args: any[]) => void; export interface IWeb3asyWindow { address: string; networks: INetwork[]; connect: (chainId: string, projectId: string, session: string, endPoint: string, apiKey: string, callback?: TCallback, chain?: string | number) => Promise<{ accountExisted: boolean; error: Error | null; }>; disconnect: () => void; updateParams: (params: { [key: string]: string; }) => { [key: string]: string; }; createUser: (projectId: string, session: string, chain?: string | number) => Promise<string>; getAddress: (projectId: string, session: string, chain?: string | number) => Promise<string | null>; getAddressWithPubkey: (projectId: string, session: string, chain?: string | number) => Promise<{ address: string; publicKey: string; } | null>; requestTransaction: (payload: ICustonomyPayload<ITransaction | string | any>) => Promise<{ txnId: string; newAddress?: string; hex?: string; }>; } export interface INetwork { chain: string; subchain: string; network: string; chainId: number; name: string; addressReference: string; } export interface ITransaction { method?: string; from: string; to: string; gasLimit: number; gasPrice: number; nonce: string; value: string; data: string; type: number; chainId?: number; } export interface ICustonomyPayload<T = unknown> { method: string; params: T; chainId?: number; } export interface Web3asyWindow extends Window { custonomy?: IWeb3asyWindow | null; } export interface Web3asyParams { network: WEB3ASY_NETWORK; projectId: string; session?: string; endPoint: string; apiKey: string; apiSecret?: string; rpcEndPoint?: string; rpcEndPointApiKey?: string; callback?: TCallback; window?: Web3asyWindow; }