npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

platrust-wallet-js-sdk

v1.0.1

Published

The EIP-4337 library for platrust-Wallet

Downloads

6

Readme

Table of Contents

Features

  • All-In-One

  • UserOperation can be built with a single function

  • Built-in Bundler module

  • Built-in common operations, such as ERC20 ERC721 ERC1155 (e.g. you can create a transfer UserOperation with one function)

  • Auto update preVerificationGas (lower deposit requirements for user)

  • ⚠️ Note: current version will refactor the code in the future and cannot guarantee compatibility

Installing

Using npm:

$ npm install git+https://github.com/PlatONnetwork/platrust-wallet-js-sdk.git#v0.1.0

Using yarn:

$ yarn add git+https://github.com/PlatONnetwork/platrust-wallet-js-sdk.git#v0.1.0

Using pnpm:

$ pnpm add git+https://github.com/PlatONnetwork/platrust-wallet-js-sdk.git#v0.1.0

Once the package is installed, you can import the library using import approach:

import { ApproveToken, ParsedTransaction, walletLib, UserOperation } from 'platrust-wallet-js-sdk';

Example

import { ethers } from "ethers";
import { Accounts } from "web3-eth-accounts";
import { UserOpReceipt, walletLib, UserOperation, packSignatureHash, signMessage, encodeSignature } from 'platrust-wallet-js-sdk';

async function main() {
    const pks = ['0xa5748918ff73de2e3f6cde786a1567640349eefff2503de82b0bfa4d41d55101']
    let owners = ['0x2E64cAbc8586CE95B5744DDE91Bc92182CbbD813']

    const walletLib = new walletLib();
    const walletLogic = '0x2e234DAe75C793f67A35089C9d99245E1C58470b'
    const walletFactory = '0xF62849F9A0B5Bf2913b396098F7c7019b51A820a' // wallet proxy factory contract address
    const relayerManagerAddr = '0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f'
    // const salt = ethers.utils.formatBytes32String("abc")
    const salt = '0x4aa639acfa86f7d60530bf462efdfdd9f4c4a6526226f5284c0af71240d47f25'
    console.log("relayer: ", relayerManagerAddr);

    const initializer = await walletLib.getSetupCode(
        relayerManagerAddr,   // <address> EntryPoint Contract Address
        owners, // <[address]> owner Address List
        1,       // <number> threshold
        AddressZero,  // <address> to Address
        '0x',  // <string> wallet init execute data
        AddressZero,  // <string> fallbackHandler
        86400,      // <number> lockPerid
    )
    const walletAddress = await walletLib.calculateWalletAddress(
        walletLogic,  // <address> walletLogic Contract Address
        initializer,  // <string> initializer
        salt,     // <string> salt (Hex string)
        walletFactory  // <address> wallet Factory Address
    );
    console.log('initializer: ', initializer)
    // console.log("wallet: ", walletAddress);
    // console.log("factory: ", walletFactory);
    // console.log("wallet logic: ", walletLogic);
    const initcode = walletLib.getInitCode(walletFactory, walletLogic, initializer, salt)
    console.log("init code: ", initcode)
    const activateOp = walletLib.activateWalletOp(
        walletLogic,  // <address> wallet Logic Contract Address
        initializer,  // <string> initializer
        undefined,   // <bytes> paymasterAndData
        salt,     // <string> salt (Hex string)
        walletFactory,  // <address> Wallet factory Contract Address
        100,      // <number> maxFeePerGas 100Gwei
        1000,     // <number> maxPriorityFeePerGas 10Gwei
        5000000,
        500000,
        50000
    );
    console.log("user op: ", activateOp.toTuple())
    // const userOpHash = activateOp.getUserOpHash(
    //     "0x32De9126ee5bc74039ADCCe66bc00d13C6651028",  // <address> EntryPoint Contract Address
    //     2206132,                   // <uint32> chainId
    // );
    const userOpHash = await activateOp.getUserOpHashFromContract(
        relayerManagerAddr,  // <address> EntryPoint Contract Address
        new ethers.providers.JsonRpcProvider( "https://devnet2openapi.platon.network/rpc"),  // ethers.providers
    );
    console.log("userOpHash: ", userOpHash);
    
    const signedHash = packSignatureHash(userOpHash, SignatureMode.owner, 0, 0);

    console.log("signedMsg: ", signedHash);
    const sig = signMessage(signedHash, pks[0])
    console.log('sig: ', sig)
    const pk = recoverAddress(signedHash, sig)
    console.log('pk: ', pk)
    // let sigs = ''
    // for (var i = 0; i < 2; i++) {
    //     const sig = signMessage(signedHash, pks[i])
    //     sigs = ethers.utils.solidityPack(
    //         ['bytes', 'bytes'],
    //         [sigs, sig]
    //     )
    // }
    activateOp.signature = encodeSignature(SignatureMode.owner, sig, 0, 0);
    console.log("signature: ", activateOp.signature);
    
    const bundler = new BaseWalletLib.Bundler(
        '0x0',  // <address> EntryPoint Contract Address
        new ethers.providers.JsonRpcProvider( "https://devnet2openapi.platon.network/rpc"),  // ethers.providers
    );

    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();

License

MPL-2.0