Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
diff
생성일
2년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
18 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
146 행
복사
25 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
153 행
복사
import "dotenv/config"
import "dotenv/config"
import {
import {
createKernelAccount,
createKernelAccount,
createZeroDevPaymasterClient,
createZeroDevPaymasterClient,
createKernelAccountClient,
createKernelAccountClient,
복사
복사됨
복사
복사됨
addressToEmptyAccount,
} from "@zerodev/sdk"
} from "@zerodev/sdk"
import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator"
import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator"
import {
import {
signerToSessionKeyValidator,
signerToSessionKeyValidator,
ParamOperator,
ParamOperator,
serializeSessionKeyAccount,
serializeSessionKeyAccount,
deserializeSessionKeyAccount,
deserializeSessionKeyAccount,
oneAddress,
oneAddress,
} from "@zerodev/session-key"
} from "@zerodev/session-key"
import { UserOperation } from "permissionless"
import { UserOperation } from "permissionless"
import {
import {
http,
http,
Hex,
Hex,
createPublicClient,
createPublicClient,
parseAbi,
parseAbi,
encodeFunctionData,
encodeFunctionData,
복사
복사됨
복사
복사됨
Address,
} from "viem"
} from "viem"
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
import { polygonMumbai } from "viem/chains"
import { polygonMumbai } from "viem/chains"
if (
if (
!process.env.BUNDLER_RPC ||
!process.env.BUNDLER_RPC ||
!process.env.PAYMASTER_RPC ||
!process.env.PAYMASTER_RPC ||
!process.env.PRIVATE_KEY
!process.env.PRIVATE_KEY
) {
) {
throw new Error("BUNDLER_RPC or PAYMASTER_RPC or PRIVATE_KEY is not set")
throw new Error("BUNDLER_RPC or PAYMASTER_RPC or PRIVATE_KEY is not set")
}
}
const publicClient = createPublicClient({
const publicClient = createPublicClient({
복사
복사됨
복사
복사됨
chain: polygonMumbai,
transport: http(process.env.BUNDLER_RPC),
transport: http(process.env.BUNDLER_RPC),
})
})
const signer = privateKeyToAccount(process.env.PRIVATE_KEY as Hex)
const signer = privateKeyToAccount(process.env.PRIVATE_KEY as Hex)
const contractAddress = "0x34bE7f35132E97915633BC1fc020364EA5134863"
const contractAddress = "0x34bE7f35132E97915633BC1fc020364EA5134863"
const contractABI = parseAbi([
const contractABI = parseAbi([
"function mint(address _to) public",
"function mint(address _to) public",
"function balanceOf(address owner) external view returns (uint256 balance)",
"function balanceOf(address owner) external view returns (uint256 balance)",
])
])
복사
복사됨
복사
복사됨
const sessionPrivateKey = generatePrivateKey()
const sessionKeySigner = privateKeyToAccount(sessionPrivateKey)
const createSessionKey = async () => {
복사
복사됨
복사
복사됨
const createSessionKey = async (sessionKeyAddress: Address) => {
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
signer,
signer,
})
})
const masterAccount = await createKernelAccount(publicClient, {
const masterAccount = await createKernelAccount(publicClient, {
plugins: {
plugins: {
sudo: ecdsaValidator,
sudo: ecdsaValidator,
},
},
})
})
console.log("Account address:", masterAccount.address)
console.log("Account address:", masterAccount.address)
복사
복사됨
복사
복사됨
// Create an "empty account" as the signer -- you only need the public
// key (address) to do this.
const emptySessionKeySigner = addressToEmptyAccount(sessionKeyAddress)
const sessionKeyValidator = await signerToSessionKeyValidator(publicClient, {
const sessionKeyValidator = await signerToSessionKeyValidator(publicClient, {
복사
복사됨
복사
복사됨
signer:
s
essionKeySigner,
signer:
emptyS
essionKeySigner,
validatorData: {
validatorData: {
paymaster: oneAddress,
paymaster: oneAddress,
permissions: [
permissions: [
{
{
target: contractAddress,
target: contractAddress,
// Maximum value that can be transferred. In this case we
// Maximum value that can be transferred. In this case we
// set it to zero so that no value transfer is possible.
// set it to zero so that no value transfer is possible.
valueLimit: BigInt(0),
valueLimit: BigInt(0),
// Contract abi
// Contract abi
abi: contractABI,
abi: contractABI,
// Function name
// Function name
functionName: "mint",
functionName: "mint",
// An array of conditions, each corresponding to an argument for
// An array of conditions, each corresponding to an argument for
// the function.
// the function.
args: [
args: [
{
{
// In this case, we are saying that the session key can only mint
// In this case, we are saying that the session key can only mint
// NFTs to the account itself
// NFTs to the account itself
operator: ParamOperator.EQUAL,
operator: ParamOperator.EQUAL,
value: masterAccount.address,
value: masterAccount.address,
},
},
],
],
},
},
],
],
},
},
})
})
const sessionKeyAccount = await createKernelAccount(publicClient, {
const sessionKeyAccount = await createKernelAccount(publicClient, {
plugins: {
plugins: {
sudo: ecdsaValidator,
sudo: ecdsaValidator,
regular: sessionKeyValidator,
regular: sessionKeyValidator,
},
},
})
})
복사
복사됨
복사
복사됨
// Include the private key when you serialize the session key
return await serializeSessionKeyAccount(sessionKeyAccount
)
return await serializeSessionKeyAccount(sessionKeyAccount
, sessionPrivateKey
)
}
}
복사
복사됨
복사
복사됨
const useSessionKey = async (serializedSessionKey: string
) => {
const useSessionKey = async (serializedSessionKey: string
, sessionKeySigner: any
) => {
const sessionKeyAccount = await deserializeSessionKeyAccount(publicClient, serializedSessionKey
)
const sessionKeyAccount = await deserializeSessionKeyAccount(publicClient, serializedSessionKey
, sessionKeySigner
)
const kernelClient = createKernelAccountClient({
const kernelClient = createKernelAccountClient({
account: sessionKeyAccount,
account: sessionKeyAccount,
chain: polygonMumbai,
chain: polygonMumbai,
transport: http(process.env.BUNDLER_RPC),
transport: http(process.env.BUNDLER_RPC),
sponsorUserOperation: async ({ userOperation }): Promise<UserOperation> => {
sponsorUserOperation: async ({ userOperation }): Promise<UserOperation> => {
const kernelPaymaster = createZeroDevPaymasterClient({
const kernelPaymaster = createZeroDevPaymasterClient({
chain: polygonMumbai,
chain: polygonMumbai,
transport: http(process.env.PAYMASTER_RPC),
transport: http(process.env.PAYMASTER_RPC),
})
})
return kernelPaymaster.sponsorUserOperation({
return kernelPaymaster.sponsorUserOperation({
userOperation,
userOperation,
})
})
},
},
})
})
const userOpHash = await kernelClient.sendUserOperation({
const userOpHash = await kernelClient.sendUserOperation({
userOperation: {
userOperation: {
callData: await sessionKeyAccount.encodeCallData({
callData: await sessionKeyAccount.encodeCallData({
to: contractAddress,
to: contractAddress,
value: BigInt(0),
value: BigInt(0),
data: encodeFunctionData({
data: encodeFunctionData({
abi: contractABI,
abi: contractABI,
functionName: "mint",
functionName: "mint",
args: [sessionKeyAccount.address],
args: [sessionKeyAccount.address],
}),
}),
}),
}),
},
},
})
})
console.log("userOp hash:", userOpHash)
console.log("userOp hash:", userOpHash)
}
}
const main = async () => {
const main = async () => {
복사
복사됨
복사
복사됨
// The
owner
creates a
session
key
, serializes it,
and
shares it with
the
agent
.
// The
agent
creates a
public-private
key
pair
and
sends
const
serializedSessionKey = await createSessionKey()
// the public key (address) to
the
owner
.
const
sessionPrivateKey = generatePrivateKey()
const sessionKeySigner = privateKeyToAccount(sessionPrivateKey)
복사
복사됨
복사
복사됨
// The agent
re
constructs
the
session key
using the serialized value
// The owner authorizes the public key by signing it and sending
await useSessionKey(serializedSessionKey
)
// back the signature
const serializedSessionKey = await createSessionKey(sessionKeySigner.address)
// The agent
constructs
a full
session key
await useSessionKey(serializedSessionKey
, sessionKeySigner
)
}
}
main()
main()
저장된 비교 결과
원본
파일 열기
import "dotenv/config" import { createKernelAccount, createZeroDevPaymasterClient, createKernelAccountClient, } from "@zerodev/sdk" import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator" import { signerToSessionKeyValidator, ParamOperator, serializeSessionKeyAccount, deserializeSessionKeyAccount, oneAddress, } from "@zerodev/session-key" import { UserOperation } from "permissionless" import { http, Hex, createPublicClient, parseAbi, encodeFunctionData, } from "viem" import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" import { polygonMumbai } from "viem/chains" if ( !process.env.BUNDLER_RPC || !process.env.PAYMASTER_RPC || !process.env.PRIVATE_KEY ) { throw new Error("BUNDLER_RPC or PAYMASTER_RPC or PRIVATE_KEY is not set") } const publicClient = createPublicClient({ chain: polygonMumbai, transport: http(process.env.BUNDLER_RPC), }) const signer = privateKeyToAccount(process.env.PRIVATE_KEY as Hex) const contractAddress = "0x34bE7f35132E97915633BC1fc020364EA5134863" const contractABI = parseAbi([ "function mint(address _to) public", "function balanceOf(address owner) external view returns (uint256 balance)", ]) const sessionPrivateKey = generatePrivateKey() const sessionKeySigner = privateKeyToAccount(sessionPrivateKey) const createSessionKey = async () => { const ecdsaValidator = await signerToEcdsaValidator(publicClient, { signer, }) const masterAccount = await createKernelAccount(publicClient, { plugins: { sudo: ecdsaValidator, }, }) console.log("Account address:", masterAccount.address) const sessionKeyValidator = await signerToSessionKeyValidator(publicClient, { signer: sessionKeySigner, validatorData: { paymaster: oneAddress, permissions: [ { target: contractAddress, // Maximum value that can be transferred. In this case we // set it to zero so that no value transfer is possible. valueLimit: BigInt(0), // Contract abi abi: contractABI, // Function name functionName: "mint", // An array of conditions, each corresponding to an argument for // the function. args: [ { // In this case, we are saying that the session key can only mint // NFTs to the account itself operator: ParamOperator.EQUAL, value: masterAccount.address, }, ], }, ], }, }) const sessionKeyAccount = await createKernelAccount(publicClient, { plugins: { sudo: ecdsaValidator, regular: sessionKeyValidator, }, }) // Include the private key when you serialize the session key return await serializeSessionKeyAccount(sessionKeyAccount, sessionPrivateKey) } const useSessionKey = async (serializedSessionKey: string) => { const sessionKeyAccount = await deserializeSessionKeyAccount(publicClient, serializedSessionKey) const kernelClient = createKernelAccountClient({ account: sessionKeyAccount, chain: polygonMumbai, transport: http(process.env.BUNDLER_RPC), sponsorUserOperation: async ({ userOperation }): Promise<UserOperation> => { const kernelPaymaster = createZeroDevPaymasterClient({ chain: polygonMumbai, transport: http(process.env.PAYMASTER_RPC), }) return kernelPaymaster.sponsorUserOperation({ userOperation, }) }, }) const userOpHash = await kernelClient.sendUserOperation({ userOperation: { callData: await sessionKeyAccount.encodeCallData({ to: contractAddress, value: BigInt(0), data: encodeFunctionData({ abi: contractABI, functionName: "mint", args: [sessionKeyAccount.address], }), }), }, }) console.log("userOp hash:", userOpHash) } const main = async () => { // The owner creates a session key, serializes it, and shares it with the agent. const serializedSessionKey = await createSessionKey() // The agent reconstructs the session key using the serialized value await useSessionKey(serializedSessionKey) } main()
수정본
파일 열기
import "dotenv/config" import { createKernelAccount, createZeroDevPaymasterClient, createKernelAccountClient, addressToEmptyAccount, } from "@zerodev/sdk" import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator" import { signerToSessionKeyValidator, ParamOperator, serializeSessionKeyAccount, deserializeSessionKeyAccount, oneAddress, } from "@zerodev/session-key" import { UserOperation } from "permissionless" import { http, Hex, createPublicClient, parseAbi, encodeFunctionData, Address, } from "viem" import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" import { polygonMumbai } from "viem/chains" if ( !process.env.BUNDLER_RPC || !process.env.PAYMASTER_RPC || !process.env.PRIVATE_KEY ) { throw new Error("BUNDLER_RPC or PAYMASTER_RPC or PRIVATE_KEY is not set") } const publicClient = createPublicClient({ transport: http(process.env.BUNDLER_RPC), }) const signer = privateKeyToAccount(process.env.PRIVATE_KEY as Hex) const contractAddress = "0x34bE7f35132E97915633BC1fc020364EA5134863" const contractABI = parseAbi([ "function mint(address _to) public", "function balanceOf(address owner) external view returns (uint256 balance)", ]) const createSessionKey = async (sessionKeyAddress: Address) => { const ecdsaValidator = await signerToEcdsaValidator(publicClient, { signer, }) const masterAccount = await createKernelAccount(publicClient, { plugins: { sudo: ecdsaValidator, }, }) console.log("Account address:", masterAccount.address) // Create an "empty account" as the signer -- you only need the public // key (address) to do this. const emptySessionKeySigner = addressToEmptyAccount(sessionKeyAddress) const sessionKeyValidator = await signerToSessionKeyValidator(publicClient, { signer: emptySessionKeySigner, validatorData: { paymaster: oneAddress, permissions: [ { target: contractAddress, // Maximum value that can be transferred. In this case we // set it to zero so that no value transfer is possible. valueLimit: BigInt(0), // Contract abi abi: contractABI, // Function name functionName: "mint", // An array of conditions, each corresponding to an argument for // the function. args: [ { // In this case, we are saying that the session key can only mint // NFTs to the account itself operator: ParamOperator.EQUAL, value: masterAccount.address, }, ], }, ], }, }) const sessionKeyAccount = await createKernelAccount(publicClient, { plugins: { sudo: ecdsaValidator, regular: sessionKeyValidator, }, }) return await serializeSessionKeyAccount(sessionKeyAccount) } const useSessionKey = async (serializedSessionKey: string, sessionKeySigner: any) => { const sessionKeyAccount = await deserializeSessionKeyAccount(publicClient, serializedSessionKey, sessionKeySigner) const kernelClient = createKernelAccountClient({ account: sessionKeyAccount, chain: polygonMumbai, transport: http(process.env.BUNDLER_RPC), sponsorUserOperation: async ({ userOperation }): Promise<UserOperation> => { const kernelPaymaster = createZeroDevPaymasterClient({ chain: polygonMumbai, transport: http(process.env.PAYMASTER_RPC), }) return kernelPaymaster.sponsorUserOperation({ userOperation, }) }, }) const userOpHash = await kernelClient.sendUserOperation({ userOperation: { callData: await sessionKeyAccount.encodeCallData({ to: contractAddress, value: BigInt(0), data: encodeFunctionData({ abi: contractABI, functionName: "mint", args: [sessionKeyAccount.address], }), }), }, }) console.log("userOp hash:", userOpHash) } const main = async () => { // The agent creates a public-private key pair and sends // the public key (address) to the owner. const sessionPrivateKey = generatePrivateKey() const sessionKeySigner = privateKeyToAccount(sessionPrivateKey) // The owner authorizes the public key by signing it and sending // back the signature const serializedSessionKey = await createSessionKey(sessionKeySigner.address) // The agent constructs a full session key await useSessionKey(serializedSessionKey, sessionKeySigner) } main()
비교하기