UNPKG

better-near-auth

Version:

Sign in with NEAR (SIWN) plugin for Better Auth

73 lines 3.38 kB
import { TransactionBuilder } from "near-kit"; import type { Near as NearType } from "near-kit"; import type { BetterAuthClientPlugin, BetterAuthClientOptions, BetterFetch, BetterFetchResponse, ClientStore } from "better-auth/client"; import { atom } from "nanostores"; import type { siwn } from "./index.js"; import { type AccountId, type NonceRequestT, type NonceResponseT, type ProfileResponseT, type VerifyRequestT, type VerifyResponseT, type RelayResponseT, type RelayStatusResponseT, type NearAccount, type ViewContractRequestT, type ViewContractResponseT, type RelayerInfo, type RelayHistoryResponseT } from "./types.js"; export interface AuthCallbacks { onSuccess?: () => void; onError?: (error: Error & { status?: number; code?: string; }) => void; } export interface SIWNClientConfig { recipient: string; networkId?: "mainnet" | "testnet"; } export interface SIWNClientActions { near: { nonce: (params: NonceRequestT) => Promise<BetterFetchResponse<NonceResponseT>>; verify: (params: VerifyRequestT) => Promise<BetterFetchResponse<VerifyResponseT>>; getProfile: (accountId?: AccountId) => Promise<BetterFetchResponse<ProfileResponseT>>; view: (params: ViewContractRequestT) => Promise<BetterFetchResponse<ViewContractResponseT>>; getAccountId: () => string | null; getState: () => { accountId: string | null; publicKey: string | null; networkId: string; } | null; isWalletConnected: () => boolean; ensureConnected: () => Promise<boolean>; disconnect: () => Promise<void>; link: (callbacks?: AuthCallbacks) => Promise<void>; unlink: (params: { accountId: string; network?: "mainnet" | "testnet"; }) => Promise<BetterFetchResponse<{ success: boolean; message: string; }>>; listAccounts: () => Promise<BetterFetchResponse<{ accounts: NearAccount[]; }>>; buildSignedDelegateAction: (receiverId: string, buildActions: (builder: TransactionBuilder, receiverId: string) => TransactionBuilder) => Promise<string>; relayTransaction: (params: { payload: string; }) => Promise<BetterFetchResponse<RelayResponseT>>; getRelayStatus: (txHash: string) => Promise<BetterFetchResponse<RelayStatusResponseT>>; getRelayerInfo: () => Promise<BetterFetchResponse<RelayerInfo & { enabled: boolean; }>>; relayHistory: () => Promise<BetterFetchResponse<RelayHistoryResponseT>>; client: NearType; }; signIn: { near: (callbacks?: AuthCallbacks) => Promise<void>; }; } export interface SIWNClientPlugin extends BetterAuthClientPlugin { id: "siwn"; $InferServerPlugin: ReturnType<typeof siwn>; getAtoms: ($fetch: BetterFetch) => { nearState: ReturnType<typeof atom<{ accountId: string | null; publicKey: string | null; networkId: string; } | null>>; walletConnected: ReturnType<typeof atom<boolean>>; }; getActions: ($fetch: BetterFetch, $store: ClientStore, options: BetterAuthClientOptions | undefined) => SIWNClientActions; } export declare const siwnClient: (config: SIWNClientConfig) => SIWNClientPlugin; //# sourceMappingURL=client.d.ts.map