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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fhevm-universal-sdk

v0.1.0

Published

Universal SDK untuk integrasi FHEVM di aplikasi web dan React.

Downloads

4

Readme

fhevm-universal-sdk

Universal SDK untuk integrasi FHEVM di aplikasi web dan React.

Instalasi

pnpm add fhevm-universal-sdk

Peer dependencies:

  • ethers (v6)
  • @zama-fhe/relayer-sdk (>= 0.2.0)
  • react (v18 atau v19) untuk adapter React

Core Usage (tanpa React)

import { createInstanceWithRelayer } from "fhevm-universal-sdk";
import { ethers } from "ethers";

async function main() {
  const rpcUrl = process.env.RPC_URL!; // set environment
  const relayerUrl = process.env.RELAYER_URL!; // URL relayer Zama
  const aclAddress = process.env.ACL_ADDRESS; // opsional, jika ada

  const provider = new ethers.JsonRpcProvider(rpcUrl);
  const chainId = (await provider.getNetwork()).chainId;

  const fhevm = await createInstanceWithRelayer({
    ethersProvider: provider,
    relayerUrl,
    chainId,
    aclContractAddress: aclAddress,
  });

  // Contoh membuat input terenkripsi untuk kontrak
  const contractAddress = "0xYourContract";
  const encrypted = await fhevm
    .createEncryptedInput(contractAddress)
    .add(123n)
    .encrypt();

  console.log("ciphertext:", encrypted);
}

React Usage (hooks)

import { useEffect } from "react";
import { ethers } from "ethers";
import { useFhevm, useFHEEncryption, useFHEDecrypt } from "fhevm-universal-sdk/react";

export default function Page() {
  const rpcUrl = process.env.NEXT_PUBLIC_RPC_URL!;
  const relayerUrl = process.env.NEXT_PUBLIC_RELAYER_URL!;
  const contractAddress = process.env.NEXT_PUBLIC_CONTRACT_ADDRESS!;

  const provider = new ethers.JsonRpcProvider(rpcUrl);

  const { status, message, error, fhevm, init } = useFhevm({
    ethersProvider: provider,
    relayerUrl,
  });

  const { canEncrypt, encryptWith } = useFHEEncryption({
    fhevm,
    contractAddress,
    // gunakan signer dari wallet (contoh: window.ethereum)
    ethersSigner: new ethers.Wallet("<private-key>", provider),
  });

  const { state, requestDecrypt } = useFHEDecrypt({
    fhevm,
    relayerUrl,
    contractAddress,
    ethersSigner: new ethers.Wallet("<private-key>", provider),
  });

  useEffect(() => {
    if (status === "idle") init();
  }, [status, init]);

  return (
    <div>
      <p>Status: {status}</p>
      {message && <p>{message}</p>}
      {error && <p>Error: {String(error)}</p>}

      <button
        disabled={!canEncrypt}
        onClick={async () => {
          const input = await encryptWith((builder) => builder.add(42n).encrypt());
          console.log("encrypted input", input);
        }}
      >
        Encrypt 42
      </button>

      <button
        onClick={async () => {
          const res = await requestDecrypt({
            // payload/result ciphertext dari kontrak
            ciphertext: "0x...",
            // domain & types EIP-712 sesuai kontrak
            domain: { name: "FHEVM", version: "1", chainId: 1337 },
            types: { /* isi EIP-712 types */ },
          });
          console.log("decrypted:", res);
        }}
      >
        Request Decrypt
      </button>
    </div>
  );
}

Publish

  1. Build paket: pnpm --filter ./packages/fhevm-universal-sdk build
  2. Login npm (sekali saja, interaktif): npm login
  3. Atur token via PowerShell (opsional):
$env:NPM_TOKEN = "<your-token>"
npm config set //registry.npmjs.org/:_authToken $env:NPM_TOKEN
  1. Publish scoped package: npm publish --access public (jalankan di folder paket)