export type ApiTonProof = {timestamp: number, domain_len: number, domain_val: string, payload: string, signature: string}; export type ApiProofValidationRequest = {public_key: string, wallet_state_init: unknown, proof: ApiTonProof}; export type CreateApiV1ProfileAddressProofArgs = {address: string, body: ApiProofValidationRequest}; export type CreateApiV1ProfileAddressProofOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Validate TON proof for given account address * * POST /v1/profile/{address}/proof */ export const createApiV1ProfileAddressProof = async (args: CreateApiV1ProfileAddressProofArgs, options?: CreateApiV1ProfileAddressProofOptions) => { const {baseUrl = "https://backend.swap.coffee", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKey !== undefined) headers.set("X-Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/profile/${encodeURIComponent(String(args.address))}/proof${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };