import { ParaClient } from '../para-client.js';
import type { SignRawResponse } from '../types.js';
export const definition = {
name: 'sign_raw',
description:
'Sign arbitrary data with a wallet via MPC. The data must be a 0x-prefixed hex string. The wallet must be in "ready" status. Returns the signature.',
inputSchema: {
type: 'object' as const,
properties: {
walletId: {
type: 'string',
description: 'The wallet ID to sign with',
},
data: {
type: 'string',
description: 'Data to sign as a 0x-prefixed hex string (e.g. "0x48656c6c6f")',
},
},
required: ['walletId', 'data'],
},
};
export async function handler(client: ParaClient, args: Record<string, unknown>) {
const walletId = args.walletId as string;
const data = args.data as string;
if (!data.startsWith('0x') || !/^0x[0-9a-fA-F]+$/.test(data)) {
return {
content: [
{
type: 'text' as const,
text: 'Error: data must be a 0x-prefixed hex string (e.g. "0x48656c6c6f"). To sign a UTF-8 string, first convert it to hex.',
},
],
isError: true,
};
}
const result = await client.requestWithRetry<SignRawResponse>(
`/v1/wallets/${walletId}/sign-raw`,
{ method: 'POST', body: { data } },
);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(result, null, 2),
},
],
};
}