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

eth-delegatable-utils

v4.1.2

Published

A JavaScript library for more easily managing invite links and signatures for [The Delegatable Framework](https://mirror.xyz/0x55e2780588aa5000F464f700D2676fD0a22Ee160/pTIrlopsSUvWAbnq1qJDNKU1pGNLP8VEn1H8DSVcvXM).

Downloads

56

Readme

Eth Delegatable Utils

A JavaScript library for more easily managing invite links and signatures for The Delegatable Framework.

Installation

npm install eth-delegatable-utils -S

Usage

To understand how Delegatable works, it might help to review the types it involves.

In short:

  • Any user can sign a delegation message.
  • A delegation can have any number of caveats.
  • A caveat specifies a contract that has the right to reject a proposed transaction.
  • A transaction is specified within an invocation.
  • An invocation is included in the batch of an invocations object (sorry!)
  • Each invocation has an authority which is either an empty array (to be a normal MetaTransaction) or is an array of delegation objects that chain from the original signer to act as, up to the signer of this invocation.
  • A SignedInvocations object is an authorized set of invocations to perform.
import { createMembership } from 'eth-delegatable-utils';

// To initialize, you need the basic EIP-712 domain info:
const contractInfo = {
  chainId: 1337,
  verifyingContract: '0x336E14B1723Dc5A57769F0aa5C409F476Ee8B333',
  name: "PhisherRegistry",
}

// You can initialize a membership with a private key to allow a key to delegate:
const aliceMembership = createMembership({
  contractInfo,
  key: PRIV_KEY,
});

// Users can create invitations of their own
// Providing no arguments will result in an invitation that includes a key
// The recipient has to trust the sender, but hey, they already kinda did.
// The invitation object is JSON-serializable.
const invitation = aliceMembership.createInvitation();

// Memberships can be initialized with `invitation` objects:
const bobMembership = createMembership({
  contractInfo,
  invitation,
});

// Invitations can also include arbitrary caveats, which are enforced by CaveatEnforcer contracts.
// https://github.com/danfinlay/delegatable-eth/tree/main/packages/hardhat/contracts/caveat-enforcers
// If no `delegation` paramter is provided, a default one is generated that points at the verifyingContract.
const carolInvitation = bobMembership.createInvitation({
  delegation: {
    caveats: [
      {
        enforcer: ENFORCER_CONTRACT_ADDRESS,
        terms: BYTES_TERMS_INTERPRETED_BY_ENFORCER,
      }
    ],
  }
});


// Users can then sign invocations with their memberships.
// First we'll construct an invocation.
// Here's how you would use ethers to generate transaction data for a MetaTransaction.
// We'll add a better convenience method for this kind of thing later:
const desiredTx = await registry.populateTransaction.claimIfPhisher(`TWT:${_phisher.toLowerCase()}`, true);
const invocation = {
  transaction: {
    to: address,
    data: desiredTx.data,
    gasLimit: 500000,
  },
  authority: signedDelegations,
}

// The nonces don't need to block here because we also have a queue for the nonces.
// If you don't want to keep track of the nonces you can usually just pick a random queue.
const queue = Math.floor(Math.random() * 100000000);

// Then you can just sign the invocations:
const signedInvocations = carolMembership.signInvocations({
  batch: invocations,
  replayProtection: {
    nonce: 1,
    queue,
  }
});

// Once the invocations are signed, then you can just call the `invoke()` function.
// Anyone can do this. They're just relaying the transaction now. The invocation signing
// is what authorized it.
return await registry.invoke([signedInvocations]);