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/browser-utilities

v1.0.1

Published

Basic functions for PORPOISE Network clients

Downloads

6

Readme

🐬 PORPOISE Network Browser Utilities

This is a simple typescript package for PORPOISE clients with no external dependencies. It implements the functions needed for survey commitments, survey roots, and inclusion proofs that are compatible with the PORPOISE oracle contracts.

See the PORPOISE survey standard and commitment protocol for more information.

Install

If you are using the PORPOISE browser utilities in a React app (or something similar), install from npm:

npm install --save @zkporpoise/browser-utilities

Alternatively, include the package with a script tag in your html via UNPKG:

<script src="https://unpkg.com/@zkporpoise/[email protected]/dist/index.js"></script>

Methods

  • computeMerkleRoot(leafs: ArrayBuffer[], proof: ArrayBuffer[], 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.

  • arrayBufferToHex(arrayBuffer: ArrayBuffer): converts an ArrayBuffer to a hex string.

Examples

    test('Compute the Merkle Root of a survey', () => {
        const dolphin = "When Moon?";
        const alarmclock = 1708898357455;
        const hexAlarmClock = mapBigIntTo256BitNumber(BigInt(alarmclock));
        const oracle = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
        const option1 = "Soon";
        const option2 = "NGMI";

        // expected results
        const surveyRoot = 'fbe8df6fbca5d1d3b8d1a1fde29187414985123c7b23c292630b4643c6e0e792';
        const proof1 = '1bea05448b2915e8c8aabb7b3b2aefca39dd08a667f5f1b86826cfec4724f1dd';
        const proof2 = '1003f681e3e7ac40f94da4da04a359cc066c10c4cbc1e22e26aa2e7215b281f6';
        const proof3 = '0bf89986e3662d6b50568f6a9ea422648cea72453bc7e736a29f7905869b29e5';


        return padArrayToPowerOfTwo([dolphin, hexAlarmClock, oracle, option1, option2], '0')
            .then((paddedComponents) => {
                return computeMerkleRoot(paddedComponents, [], 1);
            })
            .then((result) => {
                expect(result.length).toBe(2);
                const hexProof = result[1].map(buf => arrayBufferToHex(buf));
                expect(arrayBufferToHex(result[0])).toBe(surveyRoot);
                expect(hexProof[0]).toContain(proof1);
                expect(hexProof[1]).toContain(proof2);
                expect(hexProof[2]).toContain(proof3);
            })
    });