SessionKeySigner

Defined in: account-kit/smart-contracts/dist/types/src/msca/plugins/session-key/signer.d.ts:21

A simple session key signer that uses localStorage or sessionStorage to store a private key. If the key is not found, it will generate a new one and store it in the storage.

Implements

  • SmartAccountSigner<LocalAccountSigner<PrivateKeyAccount>>

Constructors

Constructor

1new SessionKeySigner(config_?): SessionKeySigner;

Defined in: account-kit/smart-contracts/dist/types/src/msca/plugins/session-key/signer.d.ts:38

Initializes a new instance of a session key signer with the provided configuration. This will set the signerType, storageKey, and storageType. It will also manage the session key, either fetching it from storage or generating a new one if it doesn’t exist.

Example

1import { SessionKeySigner } from "@account-kit/smart-contracts";
2
3const signer = new SessionKeySigner();

Parameters

ParameterTypeDescription

config_?

{ storageKey?: string; storageType?: Storage | "local-storage" | "session-storage"; }

the configuration for initializing the session key signer

config_.storageKey?

string

config_.storageType?

Storage | "local-storage" | "session-storage"

Returns

SessionKeySigner

Properties

PropertyTypeDescription

generateNewKey

() => `0x${string}`

Generates a new private key and stores it in the storage.

Example

1import { SessionKeySigner } from "@account-kit/smart-contracts";
2
3const signer = new SessionKeySigner();
4const newSessionKey = signer.generateNewKey();

getAddress

() => Promise<`0x${string}`>

An async function that retrieves the address using the inner object’s getAddress method.

Example

1import { SessionKeySigner } from "@account-kit/smart-contracts";
2
3const signer = new SessionKeySigner();
4const sessionKeyAddress = await signer.getAddress();

inner

LocalAccountSigner<{ address: `0x${string}`; nonceManager?: NonceManager; publicKey: `0x${string}`; sign: (parameters) => Promise<`0x${string}`>; signAuthorization: (parameters) => Promise<SignAuthorizationReturnType>; signMessage: (__namedParameters) => Promise<`0x${string}`>; signTransaction: <serializer, transaction>(transaction, options?) => Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, `0x${string}`> extends true ? TransactionSerialized<GetTransactionType<transaction>> : `0x${string}`>; signTypedData: <typedData, primaryType>(parameters) => Promise<`0x${string}`>; source: "privateKey"; type: "local"; }>

signerType

string

signMessage

(msg) => Promise<`0x${string}`>

Signs a message using the inner signer.

Example

1import { SessionKeySigner } from "@account-kit/smart-contracts";
2
3const signer = new SessionKeySigner();
4const sessionKeyAddress = await signer.signMessage("hello");

signTypedData

<TTypedData, TPrimaryType>(params) => Promise<`0x${string}`>

Signs the provided typed data using the inner signer.

Example

1import { SessionKeySigner } from "@account-kit/smart-contracts";
2
3const signer = new SessionKeySigner();
4console.log(await signer.signTypedData({
5 types: {
6 "Message": [{ name: "content", type: "string" }]
7 },
8 primaryType: "Message",
9 message: { content: "Hello" },
10}));