verifyTypedData
Action for verifying signed Starknet typed data.
Import
import { verifyTypedData } from "starkweb/core";
Usage
index.ts
import { verifyTypedData } from "starkweb/core";
import { config } from "./config";
const isValid = await verifyTypedData(config, {
types: {
StarknetMessage: [
{ name: "message", type: "felt" },
],
},
primaryType: "StarknetMessage",
message: {
message: "Hello Starknet!",
},
signature: ["0x123...", "0x456..."],
publicKey: "0x789...",
});
Parameters
import { type VerifyTypedDataParameters } from "starkweb/core";
types
TypedData
The type definitions for the structured data.
primaryType
string
The primary type that was signed.
message
Record<string, unknown>
The structured data that was signed.
signature
Hex[]
The signature components to verify.
publicKey
Hex
The public key to verify against.
index.ts
import { verifyTypedData } from "starkweb/core";
import { config } from "./config";
const isValid = await verifyTypedData(config, {
types: {
StarknetMessage: [
{ name: "message", type: "felt" },
],
},
primaryType: "StarknetMessage",
message: {
message: "Hello Starknet!",
},
signature: ["0x123...", "0x456..."],
publicKey: "0x789...",
});
chainId (optional)
Hex | undefined
The chain ID to verify on. If not provided, uses the current chain.
index.ts
import { verifyTypedData } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
const isValid = await verifyTypedData(config, {
types: {...},
primaryType: "StarknetMessage",
message: {...},
signature: ["0x123...", "0x456..."],
publicKey: "0x789...",
chainId: mainnet.chain_id,
});
Return Type
import { type VerifyTypedDataReturnType } from "starkweb/core";
boolean
Whether the signature is valid.
Example
example.ts
import { verifyTypedData } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
// Verify on current chain
const isValid = await verifyTypedData(config, {
types: {
StarknetMessage: [
{ name: "message", type: "felt" },
],
},
primaryType: "StarknetMessage",
message: {
message: "Hello Starknet!",
},
signature: ["0x123...", "0x456..."],
publicKey: "0x789...",
});
console.log("Is signature valid?", isValid);
// Verify on specific chain
const isValidOnMainnet = await verifyTypedData(config, {
types: {...},
primaryType: "StarknetMessage",
message: {...},
signature: ["0x123...", "0x456..."],
publicKey: "0x789...",
chainId: mainnet.chain_id,
});
Error
import { type VerifyTypedDataErrorType } from "starkweb/core";