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 🙏

© 2026 – Pkg Stats / Ryan Hefner

permit2-helper

v0.0.1

Published

Signature creation helper for Uniswap Permit2

Readme

Permit2-helper

Overview

This library is designed to simplify interaction with the Uniswap Permit2 smart contract, which adds "permit" functionality to tokens that don't support it.

To learn more about why Permit2 was created and what its logic is:


Let's get started

  1. First, you need to install the library:
npm install permit2-helper
  1. Import the library at the beginning of your script:
import { Permit2 } from "permit2-helper";
  1. Create an instance of the class:
/*
Constructor takes object of parameters, it's interface:
    interface Permit2ConstructorParams {
    	signer?: SignerLike;
    	domainOpt?: DomainOptions;
    }

    interface DomainOptions {
    	chainId?: ethers.BigNumberish;
    	verifyingContract?: string;
    }
*/
const permit2Helper = new Permit2({
	signer: YourSigner,
	domainOpt: { chaindId: YourChainId, verifyingContract: YourVerifier },
});
  1. Call the function to sign the message (see below)

signPermitTransferFrom & signPermitWitnessTransferFrom


You probably only need two functions:

signPermitTransferFrom

signPermitTransferFrom args:

  • params: PermitTransferFromArgs, see code snippet
  • domainOptions?: DomainOptions | null, --> if you want to override default domain in class
  • signer?: SignerLike | null, --> if you want to override default signer in class
/*
    interface PermitTransferFromArgs {
	    permitted: TokenPermissions; --> desired token and amount which you will approve to spender
	    spender: string; --> approve receiver
	    nonce: ethers.BigNumberish; --> your nonce for this approve
	    deadline: ethers.BigNumberish; --> block.timestamp when approve will expired
    }

    interface TokenPermissions {
	    token: string;
	    amount: string | BigInt;
    }
*/

const params: {
        permitted: {
            token: token.address,
            amount: 123456789
        },
	    spender: spender.address,
	    nonce: 123,
	    deadline: 123456789,
}

const signature = await permit2Helper.signPermitTransferFrom(params);

signPermitWitnessTransferFrom

signPermitWitnessTransferFrom args:

  • params: PermitTransferFromArgs, --> same with signPermitTransferFrom
  • witnessValue: WitnessValue, --> your witness value (structure values)
  • witnessTypes: PermitWitnessTransferFromTypes, --> types for witness structure
  • domainOptions?: DomainOptions, --> same with signPermitTransferFrom
  • signer?: SignerLike --> same with signPermitTransferFrom
/*
    === Interfaces:
    type WitnessValue = Record<string, unknown>;

    interface PermitWitnessTransferFromTypes {
	    witnessType: ethers.TypedDataField;
	    witnessSubTypes: TypeElement;
    }
    ===

    Solidity struct for example:
        struct Witness {
		    address user;
	    }
*/

const witnessValue = {
	witness: { user: spender.address },
};

const witnessTyping = {
	witnessType: { type: "Witness", name: "witness" },
	witnessSubTypes: { Witness: [{ type: "address", name: "user" }] },
};

const signature = await permit2Helper.signPermitWitnessTransferFrom(
	paramsToSign,
	witnessValue,
	{
		witnessType: witnessTyping.witnessType,
		witnessSubTypes: witnessTyping.witnessSubTypes,
	},
);

For more examples see tests


Testing

cd ./test
npx hardhat test

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.


Author: Vladimir Kumalagov


License MIT