Skip to content

Commit

Permalink
add stop recovery script
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Nov 9, 2023
1 parent 51b6721 commit 2c07a3a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
59 changes: 59 additions & 0 deletions scripts/secp256r1/recovery-account-stop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ethers } from "hardhat"
import * as fs from "fs"
import * as path from "path"
import ecPem from "ec-pem"

import { P256AccountFactory } from "../../typechain"
import { EntryPoint } from "@account-abstraction/contracts"
import { Client, Presets } from "userop"
import { P256Account } from "../userop/p256-account"
import { P2565Signer } from "../userop/p256-signature"

// TODO need create account first
async function main() {
const rpc = "https://babel-api.testnet.iotex.io"
const bundlerRpc = "https://bundler.testnet.w3bstream.com"
const accountFactory = (await ethers.getContract("P256AccountFactory")) as P256AccountFactory
const accountTpl = await ethers.getContractFactory("P256Account")
const entryPoint = (await ethers.getContract("EntryPoint")) as EntryPoint
const client = await Client.init(rpc, {
entryPoint: entryPoint.address,
overrideBundlerRpc: bundlerRpc,
})

const keyContent = fs.readFileSync(path.join(__dirname, "key.pem"))
const keyPair = ecPem.loadPrivateKey(keyContent)
const signer = new P2565Signer(keyPair)

const accountBuilder = await P256Account.init(signer, rpc, {
overrideBundlerRpc: bundlerRpc,
factory: accountFactory.address,
entryPoint: entryPoint.address,
salt: 0,
paymasterMiddleware: Presets.Middleware.verifyingPaymaster(
// paymaster rpc
`https://paymaster.testnet.w3bstream.com/rpc/${process.env.API_KEY}`,
""
),
})
const account = accountBuilder.getSender()

const callData = accountTpl.interface.encodeFunctionData("execute", [
account,
0,
accountTpl.interface.encodeFunctionData("stopRecovery", []),
])
accountBuilder.setCallData(callData)

const response = await client.sendUserOperation(accountBuilder)
console.log(`Stop recovery account ${account} ophash: ${response.userOpHash}`)
const userOperationEvent = await response.wait()
console.log(`Stop recovery account ${account} txhash: ${userOperationEvent?.transactionHash}`)
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
4 changes: 3 additions & 1 deletion scripts/secp256r1/recovery-email-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async function main() {
const account = accountBuilder.getSender()

const { chainId } = await ethers.provider.getNetwork()
const message = `Send an email with below text as subject to iopay-recover@iotex.me\n01${chainId}${account.toLowerCase()}${signer.publicKey()}`
const message = `Send an email with below text as subject to iopay-recover@iotex.me\n01${chainId}${account.toLowerCase()}${signer
.publicKey()
.substring(2)}`

console.log(message)
}
Expand Down

0 comments on commit 2c07a3a

Please sign in to comment.