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

spendguard-sdk

v1.1.0

Published

TypeScript SDK for SpendGuard: scoped session-key vaults for tUSD8 on the QDay Aevum testnet. Create a vault, grant a session key, pay within bounds, revoke in one click.

Readme

spendguard-sdk

TypeScript SDK for SpendGuard: scoped session-key vaults for tUSD8 on the QDay Aevum testnet (chain 44005). Give an agent a key that can only spend a little, only to approved merchants, only until Friday, and take it back in one click.

Built by Muhammed Adediran for the Aevum Builder Challenge #1. MIT licensed. The contracts are at ../src/, the factory is deployed at 0x3BD7Ffda8504124fb7aE9e28DCA0D01aA5A728EE, and the live app is at https://admuad.github.io/Spendguard/.

Install

npm install spendguard-sdk viem

Or, from this repo:

cd sdk && npm install && npm run build

Requires Node 20+. The only runtime dependency is viem.

Quickstart

import {
  createSpendGuardClient,
  createSpendGuardWalletClient,
  toBaseUnits,
} from "spendguard-sdk";

// Owner: create a vault, fund it, grant a key to an agent.
const owner = createSpendGuardClient({
  walletClient: createSpendGuardWalletClient("0x...owner-test-key..."),
});
const { vault, transactionHash } = await owner.createVault();
await owner.deposit(vault, toBaseUnits("3.00"));
// fundGas sends 0.01 tQDAY to the key right after the grant confirms,
// so the key can pay for its own gas. A plain transfer, not a contract call.
const { grantHash, gasFundHash } = await owner.grantSession(vault, {
  sessionKey: "0x...agent-address...",
  recipients: ["0x...merchant-address..."],
  maxPerTx: toBaseUnits("0.10"),
  spendCap: toBaseUnits("1.00"),
  expiresAt: BigInt(Math.floor(Date.now() / 1000) + 7 * 24 * 3600),
}, { fundGas: true });

// Agent: the agent holds ONLY the session key. It checks, then pays.
const agent = createSpendGuardClient({
  walletClient: createSpendGuardWalletClient("0x...agent-test-key..."),
});
const check = await agent.canSpend(vault, "0x...agent-address...", "0x...merchant-address...", toBaseUnits("0.05"));
if (check.ok) {
  await agent.executePayment(vault, "0x...agent-address...", "0x...merchant-address...", toBaseUnits("0.05"));
}

// Anyone: read state and history.
const readOnly = createSpendGuardClient();
const balance = await readOnly.vaultBalance(vault);
const payments = await readOnly.getPayments(vault);

What the SDK covers

| Area | Methods | |---|---| | Factory | createVault, vaultsOf, vaultCount, allVaults | | Owner | deposit, grantSession, editSession, revokeSession, pause, unpause, ownerWithdraw | | Session key | executePayment, canSpend (pre-flight check) | | Reads | getSession, remainingCap, vaultBalance, isRecipientAllowed, isPaused, vaultOwner, vaultToken, tokenBalance, tokenAllowance | | History | getPayments, getSessionGrants (chunked log reads) | | Helpers | toBaseUnits, fromBaseUnits, explorerTxUrl, explorerAddressUrl, createSpendGuardWalletClient |

Rules the SDK follows (so you do not have to remember them)

  • Legacy transactions. Every write uses a legacy (type 0) transaction, which is what Aevum expects.
  • 1,000-block log limit. Aevum caps eth_getLogs at 1,000 blocks. getPayments and getSessionGrants chunk their range automatically, starting from the factory deploy block.
  • Exact approvals. deposit approves exactly the deposit amount, never an unlimited allowance.
  • Pre-flight checks. canSpend mirrors the contract's checks (paused, active, expiry, per-tx limit, cap, allowlist, balance) before a payment is sent. The contract enforces the same bounds on-chain, so the check is a second layer, not the only layer.
  • One confirmation. Every write waits for its receipt and throws if the transaction reverts.
  • Gas funding for keys. A session key pays its own gas, so it needs a little tQDAY before it can pay. Pass { fundGas: true } to grantSession and the SDK sends 0.01 tQDAY to the key right after the grant confirms (pass gasFundAmount to change the amount). This is a plain native transfer, not a gasless flow. Full gasless is a roadmap item: it needs EIP-3009 on tUSD8, which the deployed token does not have, so no gasless flow via the token is possible today.

Session model

A session key may spend only within four bounds, all enforced on-chain:

  • Recipients: an allowlist. Any other recipient reverts.
  • Per-transaction cap: the largest single payment.
  • Cumulative cap: the largest total the key may ever spend.
  • Expiry: a Unix timestamp. A payment is valid only while now is before it.

The owner can revoke a key instantly, edit a live key's bounds without resetting what it already spent, pause all payments, and always sweep the full remaining balance, even while paused. Revocation is permanent: only a fresh grant resets spent to zero.

Aevum notes

  • Chain 44005, RPC https://rpc-test.qday.info (HTTPS only, no WebSocket).
  • tUSD8 0x456569838f1d43009A91ebA4263147Afd7233483, 6 decimals.
  • Explorer verification does not work on Aevum yet; the deployed addresses and the exact commit are in the repo README instead.
  • There is no officially supported bundler or paymaster for this challenge, and account abstraction is not required. This SDK uses a normal wallet plus tUSD8 payments.
  • Test tokens only. Never use a mainnet key with this SDK.

Tests

npm test          # unit tests, no network needed
npm run smoke-test  # live end-to-end run on Aevum testnet (needs a test wallet)

The smoke test creates a fresh vault through the SDK, deposits 0.10 tUSD8, grants a session key, pays 0.01 tUSD8, revokes the key, and sweeps the vault back to zero. It prints every transaction hash. It needs AEVUM_TESTNET_PRIVATE_KEY set to a TEST wallet key, and never prints the key.

Changelog

1.1.0

  • One-click gas funding: grantSession accepts { fundGas: true } and sends 0.01 tQDAY to the key right after the grant confirms, so the key can pay for its own gas. Pass gasFundAmount to change the amount.
  • Breaking change: grantSession now returns { grantHash, gasFundHash } instead of a bare transaction hash. gasFundHash is only set when gas funding was requested.

License

MIT. See ../LICENSE.