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

@vaultlayer/vincent-send-policy-counter

v0.0.9

Published

A Vincent policy that counts the number times an ability is executed

Readme

Vincent Policy: Send Policy Counter

A Vincent Policy that tracks and limits the number of native token sends per time window using an on-chain counter contract.

Overview

The Send Policy Counter provides rate limiting functionality for Vincent Abilities by tracking the number of executions per PKP within configurable time windows. It uses an on-chain smart contract to maintain reliable state and prevent double-spending.

Features

  • Tracks the number of sends executed by a PKP using a smart contract
  • Enforces maximum send limits within configurable time windows
  • Prevents double-spending by committing counts before transaction execution
  • Automatically resets counters when time windows expire
  • Integrates seamlessly with Native Send ability
  • Uses on-chain storage for reliable state management

Installation

npm install @vaultlayer/vincent-send-policy-counter
# or
pnpm add @vaultlayer/vincent-send-policy-counter
# or
yarn add @vaultlayer/vincent-send-policy-counter

Usage

Basic Policy Setup

import { bundledVincentPolicy } from '@vaultlayer/vincent-send-policy-counter';
import { createVincentAbilityPolicy } from '@lit-protocol/vincent-ability-sdk';

const SendLimitPolicy = createVincentAbilityPolicy({
  abilityParamsSchema,
  bundledVincentPolicy,
  abilityParameterMappings: {
    to: 'to', // Maps ability's 'to' parameter to policy
  },
});

With Native Send Ability

import { bundledVincentAbility } from '@vaultlayer/vincent-ability-native-send';
import { bundledVincentPolicy } from '@vaultlayer/vincent-send-policy-counter';

// Execute ability with rate limiting
const result = await executeAbility({
  ability: bundledVincentAbility,
  policy: SendLimitPolicy,
  params: {
    to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
    amount: '0.1',
  },
  policyParams: {
    maxSends: 10, // Maximum 10 sends
    timeWindowSeconds: 3600, // Per hour (3600 seconds)
  },
});

Parameters

User Parameters (Policy Configuration)

maxSends

  • Type: number
  • Required: Yes
  • Description: Maximum number of sends allowed within the time window
  • Example: 10, 100, 5

timeWindowSeconds

  • Type: number
  • Required: Yes
  • Description: Duration of the counting window in seconds
  • Example: 3600 (1 hour), 86400 (1 day), 300 (5 minutes)

Ability Parameters (Mapped from Ability)

to

  • Type: string
  • Description: The recipient's address (mapped from ability)
  • Example: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb'

Policy Phases

1. Precheck Phase

Validates if the PKP has remaining sends in the current time window.

Allow Response:

{
  currentCount: 3,        // Number of sends already made
  maxSends: 10,          // Maximum allowed sends
  remainingSends: 7,     // Sends still available
  timeWindowSeconds: 3600 // Window duration
}

Deny Response:

{
  reason: "Send limit exceeded. Maximum 10 sends per 3600 seconds. Try again in 1800 seconds.",
  currentCount: 10,      // Current count (at limit)
  maxSends: 10,         // Maximum allowed
  secondsUntilReset: 1800 // Time until reset
}

2. Evaluate Phase

Double-checks the send limit before execution to prevent race conditions.

Allow Response:

{
  currentCount: 3,        // Current count
  maxSends: 10,          // Maximum allowed
  remainingSends: 7,     // Remaining sends
  timeWindowSeconds: 3600 // Window duration
}

Deny Response:

{
  reason: "Send limit exceeded during evaluation. Maximum 10 sends per 3600 seconds. Try again in 1800 seconds.",
  currentCount: 10,      // Current count
  maxSends: 10,         // Maximum allowed
  timeWindowSeconds: 3600,
  secondsUntilReset: 1800 // Time until reset
}

3. Commit Phase

Records the send on-chain and updates the counter.

Allow Response:

{
  recorded: true,        // Successfully recorded
  newCount: 4,          // Updated count
  remainingSends: 6     // Remaining sends after commit
}

Configuration Examples

Daily Limit (24 hours)

{
  maxSends: 50,         // 50 sends per day
  timeWindowSeconds: 86400 // 24 hours
}

Hourly Limit

{
  maxSends: 10,         // 10 sends per hour
  timeWindowSeconds: 3600 // 1 hour
}

High-frequency Limit (5 minutes)

{
  maxSends: 3,          // 3 sends per 5 minutes
  timeWindowSeconds: 300 // 5 minutes
}

Weekly Limit

{
  maxSends: 100,        // 100 sends per week
  timeWindowSeconds: 604800 // 7 days
}

Use Cases

Rate Limiting

  • API Protection: Prevent abuse of payment APIs
  • User Limits: Implement per-user spending limits
  • System Protection: Prevent automated attacks

Spending Controls

  • Daily Limits: Set maximum daily spending amounts
  • Transaction Frequency: Control how often users can send
  • Security Measures: Add extra protection for high-value operations

Business Logic

  • Subscription Limits: Limit usage for subscription tiers
  • Trial Periods: Restrict functionality during trial periods
  • Compliance: Meet regulatory requirements for transaction limits

Smart Contract Integration

The policy uses an on-chain counter contract deployed on the Yellowstone testnet:

  • Contract Address: Defined in counterSignatures.address
  • Function: increment() - Records a new send
  • Storage: Maintains per-PKP counters with timestamps
  • Reset Logic: Automatically resets when time windows expire

Security Features

  • Double-spend Prevention: Commits to policy state before transaction execution
  • On-chain Storage: Uses smart contract for tamper-proof state
  • Time Window Validation: Prevents manipulation of time-based limits
  • PKP-specific Counters: Each PKP has independent counters
  • Atomic Operations: Policy commit and ability execution are coordinated

Error Handling

The policy handles various error scenarios:

  • Network Issues: Graceful handling of RPC failures
  • Contract Errors: Proper error reporting for contract calls
  • Time Window Edge Cases: Handles time window transitions
  • Counter Overflow: Prevents integer overflow issues

Dependencies

  • @lit-protocol/vincent-ability-sdk - Vincent framework
  • @lit-protocol/vincent-scaffold-sdk - Transaction utilities
  • [email protected] - Ethereum library
  • zod - Schema validation

Related Packages