import {z} from 'zod' export type GetApiGlobalWalletConsentRequestArgs = {app_id?: string | undefined, appId?: string | undefined, origin?: string | undefined, redirect_uri?: string | undefined, redirectUri?: string | undefined, scope?: string | undefined, wallet_index?: string | undefined, walletIndex?: string | undefined}; export type GetApiGlobalWalletConsentRequestOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiGlobalWalletConsentRequestResponse = z.object({ok: z.literal(true), data: z.object({app: z.object({id: z.string(), appId: z.string(), tenantId: z.string(), name: z.string(), environment: z.string().optional(), origin: z.string(), redirectUri: z.string().nullable().optional()}), requestedScopes: z.array(z.enum(["eth_accounts", "personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"])), wallet: z.object({agentId: z.string(), address: z.string(), walletIndex: z.number().int().gte(0).lte(255)}), consent: z.object({id: z.string(), tenantId: z.string(), clientId: z.string(), appId: z.string(), origin: z.string(), redirectUri: z.string().nullable().optional(), walletAgentId: z.string(), walletAddress: z.string(), walletIndex: z.number().int().gte(0).lte(255).nullable().optional(), scopes: z.array(z.enum(["eth_accounts", "personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"])), status: z.enum(["active", "revoked"]), grantedAt: z.string().nullable().optional(), lastUsedAt: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), revokedAt: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}).and(z.record(z.string(), z.unknown())).nullable()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Preview a global wallet consent request * * GET /global-wallet/consent/request */ export const getApiGlobalWalletConsentRequest = async (args: GetApiGlobalWalletConsentRequestArgs, options?: GetApiGlobalWalletConsentRequestOptions) => { const {baseUrl = "http://localhost:3200", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.app_id != null) query.append("app_id", String(args.app_id)) if (args.appId != null) query.append("appId", String(args.appId)) if (args.origin != null) query.append("origin", String(args.origin)) if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) if (args.redirectUri != null) query.append("redirectUri", String(args.redirectUri)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.wallet_index != null) query.append("wallet_index", String(args.wallet_index)) if (args.walletIndex != null) query.append("walletIndex", String(args.walletIndex)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/global-wallet/consent/request${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiGlobalWalletConsentRequestResponse, await res.json()) };