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

o1js-base64

v0.1.0

Published

This repository offers a straightforward API to encode & decode base64-encoded input bytes. It's designed to be an easy-to-use and reliable tool for encoding & decoding base64 data in various projects using [o1js](https://docs.minaprotocol.com/zkapps/o1js

Downloads

8

Readme

O1JS Base64 Encode/Decode

This repository offers a straightforward API to encode & decode base64-encoded input bytes. It's designed to be an easy-to-use and reliable tool for encoding & decoding base64 data in various projects using o1js.

How to use the package

Install the package

npm install o1js-base64

Import the provable type Bytes from o1js

import { Bytes } from 'o1js';

Base64 Decode

  1. Import the base64Decode function
import { base64Decode } from 'o1js-base64';
  1. For the example of a string input:
const encodedB64 = Bytes.fromString('7xQM+vU=');
const decodedB64 = base64Decode(encodedB64, 5);

Base64 Encode

  1. Import the base64Encode function
import { base64Encode } from 'o1js-base64';
  1. For the example of a string input:
const inputBytes = Bytes.fromString('Childish Monderino');
const encodedB64 = base64Encode(inputBytes);

Notes

  • The base64Encode and base64Decode functions are interchangeable, but base64Encode is slightly more efficient.

  • The base64Decode function will throw an error if the encodedB64 length is not a multiple of 4 or contains non-base64 characters.

  • Ensure to provide the accurate decoded byte length parameter when invoking the base64Decode function.

  • Utilize the calculateB64DecodedBytesLength function available within the package.

    • You can find an example of its usage in this code snippet.

    • If needed, you can refer to this gist for manual calculation guidance.

  • When employing the base64Decode function within a zkProgram or zkApp, it's crucial to use the appropriate provable Byte types for both input and output.

    • For reference, consider this snippet, which demonstrates a zkProgram designed to decode a base64-encoded SHA256 digest.
    • The encoded input has a length of 44, while the expected decoded output is 32 bytes long.
    • Hence, it's crucial to accurately and deterministically assign provable Byte types to match the input and output lengths.
    • Similarly, for base64 Encode, ensure the same careful consideration of Byte types.

How to build

npm run build

How to run tests

npm run test
npm run testw # watch mode

How to run coverage

npm run coverage

How to benchmark

npm run benchmark

Preview

Base64 Decode zkProgram

| Summary | | | ------------- | ---- | | Total rows | 2138 | | Generic | 1522 | | EndoMulScalar | 616 |


| Action | Time (s) | | ------- | -------- | | Compile | 1.104 | | Prove | 11.219 | | Verify | 0.844 |

Base64 Encode zkProgram

| Summary | | | ------------- | ---- | | Total rows | 1697 | | Generic | 1203 | | EndoMulScalar | 494 |


| Action | Time (s) | | ------- | -------- | | Compile | 0.667 | | Prove | 9.383 | | Verify | 1.047 |

Acknowledgement

  • This repo is inspired by the circom base64 implementation.

  • Big thanks to Gregor Mitscha-Baude for highlighting the inefficiency in processing full field elements.

    • By operating on UInt8 instead of full field elements, the base64Decode circuit rows were reduced by around 75% from 8081 to 2138.

License

Apache-2.0