UNPKG

@wauth/sdk

Version:
145 lines 5.14 kB
import PocketBase, { type RecordAuthResponse, type RecordModel } from "pocketbase"; import type { GatewayConfig, PermissionType } from "arconnect"; import Transaction from "arweave/web/lib/transaction"; import type { SignatureOptions } from "arweave/web/lib/crypto/crypto-interface"; import { type DataItem as ArConnectDataItem } from "arconnect"; declare class HTMLSanitizer { /** * Escapes HTML entities to prevent XSS attacks * @param text - The text to escape * @returns Escaped text safe for innerHTML */ static escapeHTML(text: string): string; /** * Creates a safe HTML string with basic formatting * @param text - The text content * @param allowedTags - Array of allowed HTML tags (default: ['br', 'strong', 'em']) * @returns Sanitized HTML string */ static sanitizeHTML(text: string, allowedTags?: string[]): string; /** * Safely sets innerHTML with sanitization * @param element - The DOM element * @param html - The HTML content to set * @param allowedTags - Array of allowed HTML tags */ static safeSetInnerHTML(element: HTMLElement, html: string, allowedTags?: string[]): void; /** * Creates a safe link element * @param href - The URL (will be validated) * @param text - The link text (will be escaped) * @param target - Link target (default: '_blank') * @returns HTMLAnchorElement */ static createSafeLink(href: string, text: string, target?: string): HTMLAnchorElement; } export { HTMLSanitizer }; export declare enum WAuthProviders { Google = "google", Github = "github", Discord = "discord", X = "twitter" } export declare enum WalletActions { SIGN = "sign", ENCRYPT = "encrypt", DECRYPT = "decrypt", DISPATCH = "dispatch", SIGN_DATA_ITEM = "signDataItem", SIGNATURE = "signature" } type ModalTypes = "confirm-tx" | "password-new" | "password-existing"; export type { ModalTypes }; type ModalPayload = { transaction?: Transaction; dataItem?: ArConnectDataItem; tokenDetails?: any; errorMessage?: string; }; export type { ModalPayload }; type ModalResult = { proceed: boolean; password?: string; }; export type { ModalResult }; export declare class WauthSigner { private wauth; publicKey: Buffer; ownerLength: number; signatureLength: number; signatureType: number; constructor(wauth: WAuth); setPublicKey(): Promise<void>; sign(message: Uint8Array): Promise<Uint8Array>; static verify(pk: string | Buffer, message: Uint8Array, signature: Uint8Array): Promise<boolean>; } export declare class WAuth { static devUrl: string; static devBackendUrl: string; static prodUrl: string; static prodBackendUrl: string; private pb; private authData; private wallet; private authRecord; private backendUrl; static version: string; version: string; private authDataListeners; private sessionPassword; private sessionKey; private initializeSessionKey; private storePasswordInSession; private loadPasswordFromSession; private clearSessionPassword; private clearAllAuthData; constructor({ dev, url, backendUrl }: { dev?: boolean; url?: string; backendUrl?: string; }); onAuthDataChange(callback: (data: any) => void): void; private runAction; createModal(type: ModalTypes, payload: ModalPayload | undefined, callback: (result: ModalResult) => void): Promise<void>; connect({ provider, scopes }: { provider: WAuthProviders; scopes?: string[]; }): Promise<RecordAuthResponse<RecordModel> | null>; private checkExistingWallet; private verifyPassword; addConnectedWallet(address: string, pkey: string, signature: string): Promise<any>; isLoggedIn(): boolean; getActiveAddress(): Promise<string>; getActivePublicKey(): Promise<string>; getPermissions(): Promise<PermissionType[]>; getWalletNames(): Promise<{ [x: string]: string; }>; getArweaveConfig(): Promise<GatewayConfig>; getAuthData(): RecordAuthResponse<RecordModel> | null; getAuthToken(): string | null; getWallet(): Promise<RecordModel | null>; getConnectedWallets(): Promise<RecordModel[]>; removeConnectedWallet(walletId: string): Promise<{ success: boolean; walletId: string; }>; getAuthRecord(): RecordModel | null; pocketbase(): PocketBase; sign(transaction: Transaction, options?: SignatureOptions): Promise<any>; signature(data: Uint8Array, algorithm?: AlgorithmIdentifier | RsaPssParams | EcdsaParams): Promise<Uint8Array>; signAns104(dataItem: ArConnectDataItem): Promise<{ id: string; raw: ArrayBuffer; }>; signDataItem(dataItem: ArConnectDataItem): Promise<ArrayBuffer>; getWauthSigner(): WauthSigner; getAoSigner(): (create: any, createDataItem: any) => Promise<{ id: string; raw: Buffer<ArrayBufferLike>; }>; hasSessionPassword(): boolean; refreshWallet(): Promise<void>; logout(): void; } //# sourceMappingURL=index.d.ts.map