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

@shakesco/private

v1.1.0

Published

Shakesco Stealth payments package

Downloads

7

Readme

Shakesco Stealth Addresses

Special credit to umbra-cash.

This package will allow you to perform private transactions where only the sender and receiver know the destination of the transaction. To understand how it works: umbra-docs, EIP 5564

We assume that you have a single private key securing your wallet and that you are signing the same message hash. The former is not advised.

To get started:

npm i @shakesco/private

After installing:

const shakesco = require("@shakesco/private");
const { KeyPair, RandomNumber, StealthKeyRegistry, utils } = shakesco;
const { IsUsersFunds, generateKeyPair, prepareSend } = shakesco;

We use the umbra registry to register stealth keys. To check if user has keys:

  const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
  const registry = new StealthKeyRegistry(provider);

  const { spendingPublicKey, viewingPublicKey } = await registry.getStealthKeys(recipientId);
  console.log(spendingPublicKey)
  console.log(viewingPublicKey)

If an empty string is returned the user has not registered for private transactions. So you register them as follows:

  1. If you want to set keys for a smart wallet:
   const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
   const signer = new ethers.Wallet(process.env.PRIV_KEY, provider);
   const signature = await signer.signMessage(messageHash);
   const { spendingKeyPair, viewingKeyPair } = await generateKeyPair(signature);
   console.log(viewingKeyPair.privateKeyHex);// storing this for the user is okay! To fetch transactions for them easily. You can also choose to not store it.
   const registry = new StealthKeyRegistry(provider);

   const { spendingPrefix, spendingPubKeyX, viewingPrefix, viewingPubKeyX } =await registry.setSmartStealthKeys(
        spendingKeyPair.publicKeyHex,
        viewingKeyPair.publicKeyHex);

You can call the registry contract with the above details as the parameter.

  1. If you want to set keys for EOAs:
   const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
   const { spendingKeyPair, viewingKeyPair } = await generateKeyPair(setupSig);
   const registry = new StealthKeyRegistry(provider);

   const { spendingPrefix, spendingPubKeyX, viewingPrefix, viewingPubKeyX } = await registry.SetEOAStealthKeys(
        spendingKeyPair.publicKeyHex,
        viewingKeyPair.publicKeyHex);

Your user is now ready to perform private transactions. To prepare the payee to receive a private transaction:

   const payee = //payee address
   const provider = //node provider eg: alchemy
   const { stealthKeyPair, pubKeyXCoordinate, encrypted } =
        await prepareSend(address, provider);
   console.log(stealthKeyPair.address);// address funds should be sent to. This is a stealth address that the payee can control.
   console.log(pubKeyXCoordinate); // Public key that the payee will use to decrypt the ciphertext hence proving funds belong to them
   console.log(encrypted.ciphertext);// Encrypted random number used to generate the stealth address.

NOTE📓: You need to send the ciphertext and publickey to the payee. Otherwise they will not be able to prove ownership of funds. You can use tools like the graph or moralis to query the 'Announcement' from your private contract after a transaction has been initiated.

 event Announcement(
        address indexed receiver, // put stealth address here
        uint256 amount, 
        address indexed tokenAddress,
        bytes32 pkx, //publickey here
        bytes32 ciphertext //ciphertext here
    );

To check if funds belong to a certain user:

  IsUsersFunds(object.announcements[i], provider, secret, sender).then((data) => {
      if (data.isForUser) {
        //belongs to user
        //perform any action you want with the data.
      }
    }
  );

If the funds belong to the user they can spend the funds. To create the private key that will be able to do this:

      const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
      const signer = new ethers.Wallet(process.env.PRIV_KEY, provider);
      const signature = await signer.signMessage(messageHash);
      const { spendingKeyPair, viewingKeyPair } = await generateKeyPair(
        signature
      );

      const payload = {
        ephemeralPublicKey: uncompressedPubKey,
        ciphertext: ciphertext,
      };

      const random = await viewkey.decrypt(payload);


      const privkey = KeyPair.computeStealthPrivateKey(
        spendingKeyPair.privateKeyHex,
        random //decrypted random number
      );

      const wallet = new ethers.Wallet(privkey, provider);
      const txResponse = await wallet.sendTransaction({
        value: ethers.parseEther(value),
        to: address,
      });
      const response = await txResponse.wait();

You have successfully sent a private transactions. We aim to help umbra expand the adoption of stealth payments. This will however be replaced by ZK private transactions but this is a good start to make ethereum more private!