-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
frontendFrontend developmentFrontend development
Description
概要
ERC2612のpermit署名をオフチェーンで生成するhookを実装します。
詳細
- EIP-712署名データの構築
- ウォレットでの署名リクエスト
- deadline(有効期限)の管理(デフォルト5分、変更可能)
- nonce取得
- v, r, s署名パラメータの取得
受け入れ基準
-
app/hooks/usePermitSignature.tsの作成 - EIP-712署名データ構築
- deadline設定機能(デフォルト5分)
- nonce自動取得
- 署名実行機能
- 署名結果(v, r, s, deadline)の返却
- エラーハンドリング
実装例
// app/hooks/usePermitSignature.ts
import { useCallback } from 'react';
import { signTypedData } from 'viem/actions';
export function usePermitSignature() {
const generatePermitSignature = async (
owner: string,
spender: string,
value: bigint,
deadlineMinutes: number = 5
) => {
const deadline = Math.floor(Date.now() / 1000) + deadlineMinutes * 60;
// EIP-712署名データ構築
const domain = {
name: 'FoR Token',
version: '1',
chainId: CHAIN_ID,
verifyingContract: FOR_TOKEN_ADDRESS,
};
const types = {
Permit: [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
],
};
// nonce取得とメッセージ構築
// 署名実行
return { v, r, s, deadline };
};
return { generatePermitSignature };
}技術スタック
- Viem
- EIP-712
- React 19
依存関係
- EOAウォレット接続実装後(EOAウォレット接続hook実装 #29)
- FORトークンデプロイ後(Sepoliaテストネットへのデプロイ・検証 #20)
推定工数
2日
参考
Metadata
Metadata
Assignees
Labels
frontendFrontend developmentFrontend development