Skip to content

Sign Data

Both smart wallets and classic wallets can sign text, hex, or typed data.

When signing with smart wallets, the signature is ERC-1271 compatible, so it can be verified by smart contracts and standard libraries.

Sign Text Data

import { ChainId, KriptonioSdk } from '@kriptonio/sdk';
 
const sdk = new KriptonioSdk({
  accessToken: 'your-access-token',
});
 
const wallet = await sdk.wallet.generate({
  chainId: ChainId.BaseSepolia,
  type: 'kernel',
});
 

const signature = await wallet.signMessage('hello world');

Sign Hex Data

import { ChainId, KriptonioSdk } from '@kriptonio/sdk';
 
const sdk = new KriptonioSdk({
  accessToken: 'your-access-token',
});
 
const wallet = await sdk.wallet.generate({
  chainId: ChainId.BaseSepolia,
  type: 'kernel',
});
 

const signature = await wallet.signMessage({ raw: '0x123' });

Sign Typed Data

import { ChainId, KriptonioSdk, TypedData } from '@kriptonio/sdk';
 
const sdk = new KriptonioSdk({
  accessToken: 'your-access-token',
});
 
const wallet = await sdk.wallet.generate({
  chainId: ChainId.Polygon,
  type: 'kernel',
});
 
const exampleData: TypedData = {
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' },
    ],
    Mail: [
      { name: 'from', type: 'Person' },
      { name: 'to', type: 'Person' },
      { name: 'contents', type: 'string' },
    ],
  },
  primaryType: 'Mail',
  domain: {
    name: 'Ether Mail',
    version: '1',
    chainId: wallet.chain.id,
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
  },
  message: {
    from: {
      name: 'Alice',
      wallet: wallet.address,
    },
    to: {
      name: 'Bob',
      wallet: wallet.address,
    },
    contents: 'Hello, Bob!',
  },
};
 

const signature = await wallet.signTypedData(exampleData);