account_verify_signature
Verify cryptographic signatures against a NEAR account's public key to authenticate signed data.
Instructions
Cryptographically verify a signed piece of data against a NEAR account's public key.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | The account id to verify the signature against and search for a valid public key. | |
| networkId | No | mainnet | |
| data | Yes | The data to verify. | |
| signatureArgs | Yes | The signature arguments to verify. |
Implementation Reference
- src/services.ts:1010-1010 (registration)The tool 'account_verify_signature' is registered using mcp.tool('account_verify_signature', ...) in the createMcpServer function.
mcp.tool( - src/services.ts:1011-1140 (handler)The handler function containing the entire implementation of the account_verify_signature tool. It verifies a cryptographic signature against a NEAR account's public keys by looking up the account's access keys.
'account_verify_signature', noLeadingWhitespace` Cryptographically verify a signed piece of data against a NEAR account's public key.`, { accountId: z .string() .describe( 'The account id to verify the signature against and search for a valid public key.', ), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), data: z.string().describe('The data to verify.'), signatureArgs: z .object({ curve: z.string().describe('The curve used on the signature.'), signatureData: z .string() .describe( 'The signature data to verify. Only the encoded signature data is required.', ), encoding: z .enum(['base58', 'base64']) .default('base58') .describe('The encoding used on the signature.'), }) .describe('The signature arguments to verify.'), }, async (args, _) => { const connection = await connect({ networkId: args.networkId, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const accountResult: Result<Account, Error> = await getAccount( args.accountId, connection, ); if (!accountResult.ok) { return { content: [{ type: 'text', text: `Error: ${accountResult.error}` }], }; } const accessKeys = await accountResult.value.getAccessKeys(); const message = new TextEncoder().encode(args.data); const signatureParsedResult: Result< [KeyType, Uint8Array<ArrayBufferLike>], Error > = (() => { try { const curveResult = curvePrefixToKeyType(args.signatureArgs.curve); if (!curveResult.ok) { return curveResult; } const curve = curveResult.value; switch (args.signatureArgs.encoding) { case 'base64': return { ok: true, value: [ curve, Buffer.from(args.signatureArgs.signatureData, 'base64'), ], }; case 'base58': return { ok: true, value: [curve, base58.decode(args.signatureArgs.signatureData)], }; default: throw new Error( `Unsupported encoding: ${String(args.signatureArgs.encoding)}`, ); } } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!signatureParsedResult.ok) { return { content: [ { type: 'text', text: `Unable to parse signature: ${signatureParsedResult.error}`, }, ], }; } const [curve, signature] = signatureParsedResult.value; const matchingPublicKeyCurveType = accessKeys.find( (key) => PublicKey.fromString(key.public_key).keyType === curve, ); if (!matchingPublicKeyCurveType) { return { content: [ { type: 'text', text: `Error: Unable to find a valid public key for the account ${args.accountId} with curve ${curve}`, }, ], }; } const matchingPublicKey = accessKeys.find((key) => PublicKey.fromString(key.public_key).verify(message, signature), ); if (!matchingPublicKey) { return { content: [ { type: 'text', text: `Unable to find a valid public key for the account ${args.accountId}`, }, ], }; } return { content: [ { type: 'text', text: stringify_bigint({ message: 'Found matching public key for signature verification.', publicKey: matchingPublicKey, }), }, ], }; }, ); - src/services.ts:1014-1036 (schema)The input schema for account_verify_signature defined using Zod. Accepts accountId, networkId, data (string to verify), and signatureArgs (curve, signatureData, encoding).
{ accountId: z .string() .describe( 'The account id to verify the signature against and search for a valid public key.', ), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), data: z.string().describe('The data to verify.'), signatureArgs: z .object({ curve: z.string().describe('The curve used on the signature.'), signatureData: z .string() .describe( 'The signature data to verify. Only the encoded signature data is required.', ), encoding: z .enum(['base58', 'base64']) .default('base58') .describe('The encoding used on the signature.'), }) .describe('The signature arguments to verify.'), }, - src/utils.ts:45-59 (helper)Helper function curvePrefixToKeyType used to convert a curve prefix string (like 'ed25519' or 'secp256k1') to a KeyType enum value, used in parsing the signature curve.
export const curvePrefixToKeyType = ( curvePrefix: string, ): Result<KeyType, Error> => { switch (curvePrefix.toLowerCase()) { case 'ed25519': return { ok: true, value: KeyType.ED25519 }; case 'secp256k1': return { ok: true, value: KeyType.SECP256K1 }; default: return { ok: false, error: new Error(`Unsupported curve prefix: ${curvePrefix}`), }; } };