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

@zkporpoise/node-utilities

v1.0.4

Published

This is a super-simple typescript implementation of the functions needed to generate survey roots and prediction commitments for PORPOISE that are compatible with the [PORPOISE oracle contracts](https://github.com/PORPOISE-Network/oracle-v1). This package

Downloads

15

Readme

🐬 PORPOISE Network Node Utilities

This is a super-simple typescript implementation of the functions needed to generate survey roots and prediction commitments for PORPOISE that are compatible with the PORPOISE oracle contracts. This package was designed to have no external dependences.

See the PORPOISE survey commitment protocol for more information.

Installation

npm install --save-dev @zkporpoise/node-utilities

Import

import {
  ethHexString,
  padArrayToPowerOfTwo,
  mapBigIntTo256BitNumber,
  computeMerkleRoot,
  convertProofToHex,
} from "@zkporpoise/node-utilities"

Methods

  • computeMerkleRoot(leafs: Buffer[], proof: Buffer[], tracker: number): takes output of padArrayToPowerOfTwo for leafs, an empty array, and the index of the leaf for which the proof is needed and returns an array containing the proof array, Merkle root, and root index. The proof and root can be used for registering and resolving survey on the PORPOISE oracle.

  • padArrayToPowerOfTwo(arr: string[], paddingValue: string): given an array of string elements representing a PORPOISE survey, returns sha256-hashed leaf values. Note, that leafs must be given in the order 🐬, ⏰, 🔮, 🗳️1, ... Additionally, the deadline value (⏰) is encoded as 'hex' while all other inputs are 'binary' encoded.

  • mapBigIntTo256BitNumber(bigIntValue: bigint): Converts a BigInt into a hex string so that hashes computed off-chain will match hashes computed on-chain for integers.

  • predictionCommitment(salt: string, prediction: string, surveyRoot: Buffer): Buffer: Used to calculate survey commitments from end-users.

  • ethHexString(muBuffer: Buffer): returns a 0x${string} type needed for viem

  • convertProofToHex: converts a Buffer array and Buffer and converts to 0x${string} types for use with

Example

    it("Register a survey only once.", async function () {
      const { porpacle, owner } = await loadFixture(deployPorpacle);

      const dolphin: string = "When Moon?";
      const alarmclock: number = new Date().getTime() + 86400000;
      const hexAlarmClock: string = mapBigIntTo256BitNumber(BigInt(alarmclock));
      const oracle: string = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
      const option1: string = "Soon";
      const option2: string = "NGMI";

      // the order of the array elements is important, pad values MUST be `0` string
      const paddedComponents: Buffer[] = padArrayToPowerOfTwo([dolphin, hexAlarmClock, oracle, option1, option2], '0');

      const bufferMerkleProof: [Buffer, Buffer[], number] = computeMerkleRoot(paddedComponents, [], 1);
      const stringMerkleProof: [`0x${string}`[], `0x${string}`] = convertProofToHex(bufferMerkleProof[1], bufferMerkleProof[0]);
      const proof: `0x${string}`[] = stringMerkleProof[0];
      const root: `0x${string}` = stringMerkleProof[1];

      await porpacle.write.registerSurvey([proof, root, BigInt(alarmclock)]);
      const surveyTimeouts: bigint = await porpacle.read.surveyTimeouts([root]);
      expect(surveyTimeouts).to.equal(BigInt(alarmclock));
      await expect(porpacle.write.registerSurvey([proof, root, BigInt(alarmclock)])).to.be.rejectedWith("Survey already registered");
    });