const platrust = require("platrust-wallet-js-sdk")const ethers = require("ethers")
async function main() { const pks = ['0xa5748918ff73de2e3f6cde786a1567640349eefff2503de82b0bfa4d41d55101'] let owners = ['0x2E64cAbc8586CE95B5744DDE91Bc92182CbbD813']
const walletLib = new platrust.WalletLib(); const walletLogic = '0x2e234DAe75C793f67A35089C9d99245E1C58470b' const walletFactory = '0xF62849F9A0B5Bf2913b396098F7c7019b51A820a' const relayerManagerAddr = '0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f' const salt = '0x4aa639acfa86f7d60530bf462efdfdd9f4c4a6526226f5284c0af71240d47f25' const initializer = await walletLib.getSetupCode( relayerManagerAddr, owners, 1, AddressZero, '0x', AddressZero, 86400, ) const walletAddress = await walletLib.calculateWalletAddress( walletLogic, initializer, salt, walletFactory ); const initcode = walletLib.getInitCode(walletFactory, walletLogic, initializer, salt) const activateOp = walletLib.activateWalletOp( walletLogic, initializer, undefined, salt, walletFactory, 100, 1000, 5000000, 500000, 50000 ); const userOpHash = await activateOp.getUserOpHashFromContract( relayerManagerAddr, new ethers.providers.JsonRpcProvider( "https://devnet2openapi.platon.network/rpc"), ); const signedHash = platrust.packSignatureHash(userOpHash, SignatureMode.owner, 0, 0); const sig = platrust.signMessage(signedHash, pks[0]) const pk = platrust.recoverAddress(signedHash, sig)
activateOp.signature = platrust.encodeSignature(SignatureMode.owner, sig, 0, 0); console.log("signature: ", activateOp.signature); const bundler = new walletLib.Bundler( '0x0', new ethers.providers.JsonRpcProvider( "https://devnet2openapi.platon.network/rpc"), );
const validation = await bundler.simulateValidation(activateOp); if (validation.status !== 0) { throw new Error(`error code:${validation.status}`); }
const bundlerEvent = bundler.sendUserOperation(activateOp); bundlerEvent.on('error', (err: any) => { console.log(err); }); bundlerEvent.on('send', (userOpHash: string) => { console.log('send: ' + userOpHash); }); bundlerEvent.on('receipt', (receipt: IUserOpReceipt) => { console.log('receipt: ' + JSON.stringify(receipt)); }); bundlerEvent.on('timeout', () => { console.log('timeout'); });}
main();