Skip to main content
Glama

account_sign_data

Cryptographically sign data using a local account's private key within the NEAR MCP server. Specify encoding to generate secure, encoded signatures with curve details.

Instructions

Cryptographically sign a piece of data with a local account's private key, then encode the result with the specified encoding. Outputs the curve, encoded signature, and encoding used.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesThe account id of the account that will sign the data. This account must be in the local keystore.
dataYesThe data to sign as a string.
networkIdNomainnet
signatureEncodingNoThe encoding to use for signature creation.base58

Implementation Reference

  • The handler function that retrieves the account's keypair from the keystore, signs the provided data string, encodes the signature in base58 or base64, and returns the signer account ID, curve type, encoded signature, and encoding used.
    async (args, _) => { const keyPairResult: Result<KeyPair, Error> = await getAccountKeyPair( args.accountId, args.networkId, keystore, ); if (!keyPairResult.ok) { return { content: [{ type: 'text', text: `Error: ${keyPairResult.error}` }], }; } const keyPair = keyPairResult.value; const signatureRaw = keyPair.sign(new TextEncoder().encode(args.data)); const signatureEncodingResult: Result<string, Error> = (() => { try { switch (args.signatureEncoding) { case 'base64': return { ok: true, value: Buffer.from(signatureRaw.signature).toString('base64'), }; case 'base58': return { ok: true, value: base58.encode(Buffer.from(signatureRaw.signature)), }; default: throw new Error( `Unsupported encoding: ${String(args.signatureEncoding)}`, ); } } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!signatureEncodingResult.ok) { return { content: [ { type: 'text', text: `Error: ${signatureEncodingResult.error}` }, ], }; } return { content: [ { type: 'text', text: stringify_bigint({ signerAccountId: args.accountId, curve: keyTypeToCurvePrefix(keyPair.getPublicKey().keyType), signature: signatureEncodingResult.value, encoding: args.signatureEncoding, }), }, ], }; }, );
  • Zod schema defining the input parameters: accountId (string), networkId (enum testnet/mainnet, default mainnet), data (string), signatureEncoding (enum base58/base64, default base58).
    accountId: z .string() .describe( 'The account id of the account that will sign the data. This account must be in the local keystore.', ), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), data: z.string().describe('The data to sign as a string.'), signatureEncoding: z .enum(['base58', 'base64']) .default('base58') .describe('The encoding to use for signature creation.'), },
  • MCP tool registration for 'account_sign_data' including name, description, input schema, and handler function.
    'account_sign_data', noLeadingWhitespace` Cryptographically sign a piece of data with a local account's private key, then encode the result with the specified encoding. Outputs the curve, encoded signature, and encoding used.`, { accountId: z .string() .describe( 'The account id of the account that will sign the data. This account must be in the local keystore.', ), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), data: z.string().describe('The data to sign as a string.'), signatureEncoding: z .enum(['base58', 'base64']) .default('base58') .describe('The encoding to use for signature creation.'), }, async (args, _) => { const keyPairResult: Result<KeyPair, Error> = await getAccountKeyPair( args.accountId, args.networkId, keystore, ); if (!keyPairResult.ok) { return { content: [{ type: 'text', text: `Error: ${keyPairResult.error}` }], }; } const keyPair = keyPairResult.value; const signatureRaw = keyPair.sign(new TextEncoder().encode(args.data)); const signatureEncodingResult: Result<string, Error> = (() => { try { switch (args.signatureEncoding) { case 'base64': return { ok: true, value: Buffer.from(signatureRaw.signature).toString('base64'), }; case 'base58': return { ok: true, value: base58.encode(Buffer.from(signatureRaw.signature)), }; default: throw new Error( `Unsupported encoding: ${String(args.signatureEncoding)}`, ); } } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!signatureEncodingResult.ok) { return { content: [ { type: 'text', text: `Error: ${signatureEncodingResult.error}` }, ], }; } return { content: [ { type: 'text', text: stringify_bigint({ signerAccountId: args.accountId, curve: keyTypeToCurvePrefix(keyPair.getPublicKey().keyType), signature: signatureEncodingResult.value, encoding: args.signatureEncoding, }), }, ], }; }, );
  • Helper function to retrieve the KeyPair for a given account ID and network from the keystore, used by the account_sign_data handler.
    const getAccountKeyPair = async ( accountId: string, networkId: string, keystore: UnencryptedFileSystemKeyStore, ): Promise<Result<KeyPair, Error>> => { try { const keyPair = await keystore.getKey(networkId, accountId); return { ok: true, value: keyPair }; } catch (e) { return { ok: false, error: new Error(e as string) }; } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nearai/near-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server