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

@violetprotocol/ethereum-access-token-helpers

v0.2.0

Published

Typescript bindings and utilities for Ethereum Access Token

Downloads

16

Readme

Ethereum Access Token Helpers

Utilities for the Ethereum Access Token smart contract system.

Use these tools to help you generate and sign your Ethereum Access Tokens (EATs). First ensure that your smart contracts follow appropriate EAT interfaces by ensuring all functions that intend to be modified with requiresAuth to use the following parameters prepended before your usual function parameters:

function yourFunction(uint8 v, bytes32 r, bytes32 s, uint256 expiry, ...) {}

where you insert your own function parameters in place of ....

Install

Using npm: npm install @violetprotocol/ethereum-access-token-helpers

Using yarn: yarn add @violetprotocol/ethereum-access-token-helpers

Usage

const { splitSignature } = require("@ethersproject/bytes");
const {
  signAccessToken,
  getSignerFromMnemonic, getSignerFromPrivateKey
  packParameters
} = require("@violetprotocol/ethereum-access-token-helpers/utils");

const INTERVAL: number = 100 // seconds
const FUNCTION_SIGNATURE = "0xabcdefgh";
const CONTRACT: ethers.Contract = ...; // for example an ERC20 token contract
const SIGNER: ethers.Signer = ...;
const CALLER: ethers.Signer = ...;
const VERIFIER = "0x..."; // AccessTokenVerifier contract address

const recipient = "0x123...";
const amount = 1;

// AccessToken domain for clear namespacing
const accessTokenDomain = {
  name: "Ethereum Access Token",
  version: "1",
  chainId: SIGNER.getChainId(),
  verifyingContract: VERIFIER,
};

// Construct AccessToken message with relevant data using ERC20 `transfer(address to, uint256 amount)` as the example tx
// In the AccessTokenConsumer case, the ERC20 transfer function actually looks like this:
// `transfer(uint8 v, bytes32 r, bytes32 s, uint256 expiry, address to, uint256 amount)`
// where we just augment the original function with the required parameters for auth
// the `parameters` property takes a packed, abi-encoded set of original function parameters
const accessTokenMessage = {
  expiry: Math.floor(new Date().getTime() / 1000) + interval,
  functionCall: {
    functionSignature:  FUNCTION_SIGNATURE,
    target:             CONTRACT.address.toLowerCase(),
    caller:             CALLER.address.toLowerCase(),
    parameters:         packParameters(CONTRACT.interface, "transfer", [recipient, amount]),
  },
};

// Sign the AccessToken using the Signer
const signature = splitSignature(await signAccessToken(SIGNER, accessTokenDomain, accessTokenMessage));

// Pass all signed data to a transaction function call
await CONTRACT.functionName(
  signature.v,
  signature.r,
  signature.s,
  accessTokenMessage.expiry,
  ...params
)