Skip to content

requestSignature

Usage

connect() must be called and WalletConnect session must be initiated before account information will be returned.

The requestSignature() function returns a ciphertext encryped to the currently selected account’s private key provided a string.

import { decrypt } from '@puzzlehq/sdk-core';
import { useState } from 'react';
export const Page = () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | undefined>();
const [textToSign, setTextToSign] = useState<string>('hello friends!');
const [signature, setSignature] = useState('');
const [messageFields, setMessageFields] = useState('');
const onClick = async () => {
setLoading(true);
setError(undefined);
try {
const response: SignatureResponse = await requestSignature(textToSign)
if (response.signature) setSignature(response.signature);
if (response.messageFields) setSignature(response.messageFields);
else if (response.error) setError(response.error);
} catch (e) {
setError((e as Error).message);
} finally {
setLoading(false);
}
}
return (
<div>
<input
placeholder='enter text to sign'
value={textToSign}
onChange={(e) => setTextToSign(e.target.value)}
>
<button
onClick={ onClick }
disabled={ loading || !textToDecrypt }
>
sign message
</button>
{ signature && <p>signature: {signature}</p> }
{ messageFields && <p>messageFields: {messageFields}</p> }
{ error && <p>error getting account: {error}</p> }
</div>
)
}

Types

type SignatureRequest = {
message: string;
address?: string;
};
type SignatureResponse = {
signature?: string;
messageFields?: string;
error?: string;
};