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

@1inch/permit-signed-approvals-utils

v1.5.2

Published

Utils library for EIP-2612: permit – 712-signed approvals

Downloads

2,299

Readme

Utils library for EIP-2612: permit based on EIP-712 signed approvals

This is the package of utilities for building signature and call data of EIP-2612 permits

Specification

https://eips.ethereum.org/EIPS/eip-2612

Test coverage

| Statements | Branches | Functions | Lines | | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------- | | Statements | Branches | Functions | Lines |

Installation

Node

npm install @1inch/permit-signed-approvals-utils

Yarn

yarn add @1inch/permit-signed-approvals-utils

Contributing

See CONTRIBUTING.md

Changelog

See CHANGELOG.md


About

Build permit signature

import {
    Eip2612PermitUtils,
    Web3ProviderConnector,
    PermitParams,
} from '@1inch/permit-signed-approvals-utils';
import Web3 from 'web3';

const chainId = 1;
const contractAddress = '0x11111112542d85b3ef69ae05771c2dccff4faa26';
const tokenAddress = '0x111111111117dc0aa78b770fa6a738034120c302';
const tokenName = '1INCH Token';
const walletAddress = '0x2c9b2dbdba8a9c969ac24153f5c1c23cb0e63914';
const privateKey =
    '965e092fdfc08940d2bd05c7b5c7e1c51e283e92c7f52bbf1408973ae9a9acb7';

const permitParams: PermitParams = {
    owner: walletAddress,
    spender: contractAddress,
    value: '1000000000',
    nonce: 0,
    deadline: 192689033,
};

const web3 = new Web3('...');
// You can create and use a custom provider connector (for example: ethers)
// For server side, you can use: new PrivateKeyProviderConnector(privateKey, web3);
const connector = new Web3ProviderConnector(web3);
const eip2612PermitUtils = new Eip2612PermitUtils(connector);

const signature = await eip2612PermitUtils.buildPermitSignature(
    {
        ...permitParams,
        nonce: await eip2612PermitUtils.getTokenNonce(
            tokenAddress,
            walletAddress
        ),
    },
    chainId,
    tokenName,
    tokenAddress
);

console.log('Permit signature', signature);

Build permit call data

import {
    Eip2612PermitUtils,
    Web3ProviderConnector,
    PermitParams,
} from '@1inch/permit-signed-approvals-utils';
import Web3 from 'web3';

const chainId = 1;
const contractAddress = '0x11111112542d85b3ef69ae05771c2dccff4faa26';
const tokenAddress = '0x111111111117dc0aa78b770fa6a738034120c302';
const tokenName = '1INCH Token';
const walletAddress = '0x2c9b2dbdba8a9c969ac24153f5c1c23cb0e63914';
const privateKey =
    '965e092fdfc08940d2bd05c7b5c7e1c51e283e92c7f52bbf1408973ae9a9acb7';

const permitParams: PermitParams = {
    owner: walletAddress,
    spender: contractAddress,
    value: '1000000000',
    nonce: 0,
    deadline: 192689033,
};

const web3 = new Web3('...');
// You can create and use a custom provider connector (for example: ethers)
// For server side, you can use: new PrivateKeyProviderConnector(privateKey, web3);
const connector = new Web3ProviderConnector(web3);
const eip2612PermitUtils = new Eip2612PermitUtils(connector);

const callData = await eip2612PermitUtils.buildPermitCallData(
    {
        ...permitParams,
        nonce: await eip2612PermitUtils.getTokenNonce(
            tokenAddress,
            walletAddress
        ),
    },
    chainId,
    tokenName,
    tokenAddress
);

console.log('Permit call data', callData);

Get nonce from a token contract

import {
    Eip2612PermitUtils,
    Web3ProviderConnector,
} from '@1inch/permit-signed-approvals-utils';
import Web3 from 'web3';

const tokenAddress = '0x111111111117dc0aa78b770fa6a738034120c302';
const walletAddress = '0x2c9b2dbdba8a9c969ac24153f5c1c23cb0e63914';
const privateKey =
    '965e092fdfc08940d2bd05c7b5c7e1c51e283e92c7f52bbf1408973ae9a9acb7';

const web3 = new Web3('...');
// You can create and use a custom provider connector (for example: ethers)
// For server side, you can use: new PrivateKeyProviderConnector(privateKey, web3);
const connector = new Web3ProviderConnector(web3);
const eip2612PermitUtils = new Eip2612PermitUtils(connector);

const nonce = await eip2612PermitUtils.getTokenNonce(
    tokenAddress,
    walletAddress
);

console.log('Nonce', nonce);

Recover permit owner from call data

import {
    Eip2612PermitUtils,
    Web3ProviderConnector,
} from '@1inch/permit-signed-approvals-utils';
import Web3 from 'web3';

const callData = '0x......0000';

const chainId = 56;
const tokenName = '1INCH';
const tokenAddress = '0x111111111117dc0aa78b770fa6a738034120c302';
const walletAddress = '0x2c9b2dbdba8a9c969ac24153f5c1c23cb0e63914';
const privateKey =
    '965e092fdfc08940d2bd05c7b5c7e1c51e283e92c7f52bbf1408973ae9a9acb7';

const web3 = new Web3('...');
// You can create and use a custom provider connector (for example: ethers)
// For server side, you can use: new PrivateKeyProviderConnector(privateKey, web3);
const connector = new Web3ProviderConnector(web3);
const eip2612PermitUtils = new Eip2612PermitUtils(connector);

const result = await eip2612PermitUtils.recoverPermitOwnerFromCallData({
    chainId,
    tokenName,
    tokenAddress,
    callData
});

// OR

const syncResult = eip2612PermitUtils.syncRecoverPermitOwnerFromCallData({
    chainId,
    tokenName,
    tokenAddress,
    callData,
    nonce: 1,
});

// OR (for DAI-like tokens)

const daiLikeResult = await eip2612PermitUtils.recoverDaiLikePermitOwnerFromCallData({
    chainId,
    tokenName: 'DAI',
    tokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f',
    callData,
    nonce: 1,
});

console.log('Result', result);
console.log('SyncResult', syncResult);
console.log('DaiLikeResult', daiLikeResult);