import { useTurnkey } from '@turnkey/react-wallet-kit';
import axios from 'axios';
const { httpClient } = useTurnkey();
const signed = await httpClient.stampSignRawPayload({
organizationId: session.organizationId,
signWith: <wallet_account_address>,
payload: 'hello',
encoding: 'PAYLOAD_ENCODING_TEXT_UTF8',
hashFunction: 'HASH_FUNCTION_SHA256',
});
if (!signed) throw new Error('No signed request (missing stamper?)');
const { body, stamp, url } = signed;
const xStamp =
typeof stamp === 'string' ? stamp : stamp?.stampHeaderValue;
if (!xStamp) throw new Error('Missing X-Stamp header value');
// Pass body as-is
const { data } = await axios.post(url, body, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Stamp': xStamp,
},
});
// Extract r, s, v -> signature
const { r, s, v } = data?.activity?.result?.signRawPayloadResult ?? {};
const sig = r && s && v ? (`0x${r}${s}${v}` as `0x${string}`) : undefined;
setSignature(sig ?? '(no signature returned)');
console.log('Signature:', sig);