Base64 encoding for Aztec's noir language

Overview

Noir base64

License: MIT Nargo Test ๐ŸŒŒ

Noir base64 contains functions for base64 string and u8 array encoding for Aztec's Noir language

Installation

In your Nargo.toml file, add the following dependency:

[dependencies]
base64 = { tag = "v0.1.1", git = "https://github.com/zkworks-xyz/noir-base64" }

Usage

use dep::base64;

fn main() {
    let result: [u8; 8] = base64::encode_str("foobar", [0; 8]);
}

API

Library exposes two functions:

pub fn encode_str<N, M>(input: str<N>, mut result: [u8; M]) -> [u8; M]
  • input - string to encode. Max string length is 600.
  • result - array of bytes to store result in. It should have a proper size otherwise function will fail on assert. Due to Noir language limitations result size need to be known at compile time and should be calculated by user. Value of this parameter are irrelevant, only size matters.
  • Returns result array with encoded string. Function result is also stored in mutable result array argument.
pub fn encode<N, M>(input: [u8; N], mut result: [u8; M], url_safe: bool) -> [u8; M]
  • input - array of bytes to encode. Max array size is 600.
  • result - array of bytes to store result in. It should have a proper size otherwise function will fail on assert. Due to Noir language limitations result size need to be known at compile time and should be calculated by user. Values in this array are irrelevant, only size matters.
  • url_safe - if true then + and / characters will be replaced with - and _ respectively (RFC4648)
  • Returns result array with encoded string. Function result is also stored in mutable result array argument.

Base64 decoding is not supported yet. Will be implemented in future releases.

Example project

Directory examples/base64_example/ contains example Noir project with base64 library as dependency.

License

This project is licensed under the MIT License. See the LICENSE file for details.

You might also like...
Nexa programming language. A language for game developers by a game developer
Nexa programming language. A language for game developers by a game developer

NexaLang Nexa programming language. A language for game developers by a game developer. Features High-Level: Nexa is an easy high level language Two M

A C-like programming language that is similar to Rust's syntax. Toy programming language.
A C-like programming language that is similar to Rust's syntax. Toy programming language.

CRUST This is a hobby project to learn about compilers and language design. I've designed the language to be similar to C and Rust. Heavily inspired b

A Text User Interface library for the Rust programming language
A Text User Interface library for the Rust programming language

Cursive Cursive is a TUI (Text User Interface) library for rust. It uses ncurses by default, but other backends are available. It allows you to build

Voila is a domain-specific language launched through CLI tool for operating with files and directories in massive amounts in a fast & reliable way.

Voila is a domain-specific language designed for doing complex operations to folders & files. It is based on a CLI tool, although you can write your V

Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.
Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.

2D graphics in any programming language with just print statements!

Text-based to-do management CLI & language server
Text-based to-do management CLI & language server

โ˜‘๏ธ Todome ๏ผˆๆ—ฅๆœฌ่ชž็‰ˆใฏใ“ใกใ‚‰๏ผ‰ Todome is a notation developed for making and editing to-do lists. It is inspired by Todo.txt, and in fact some of the todome not

An elegant language for script-kiddies and terminal squatters.

Tonic An elegant language for script-kiddies and terminal squatters. About I started Tonic to complete the Advent of Code 2021. My eventual goal is to

A diff-based data management language to implement unlimited undo, auto-save for games, and cloud-apps which needs to retain every change.

Docchi is a diff-based data management language to implement unlimited undo, auto-save for games, and cloud-apps which needs to save very often. User'

Rust-language assets for Zcash

Zcash Rust crates This repository contains a (work-in-progress) set of Rust crates for working with Zcash. Security Warnings These libraries are curre

Comments
  • Number conversion

    Number conversion

    • Calculate base64 result length

    • as_byte util function

    • convert_base64_number function

    • simplify convert_base64_number, add assertion, add padding support

    • Introduce url parameter

    opened by akonior 0
  • Could not resolve 'wrapping_shift_left' in path

    Could not resolve 'wrapping_shift_left' in path

    nargo test generates errors like

    error: Could not resolve 'wrapping_shift_left' in path
       โ”Œโ”€ /Users/../nargo/github.com/zkworks-xyz/noir-base64v0.1.1/src/lib.nr:55:33
       โ”‚
    55 โ”‚         let input1_last4 = std::wrapping_shift_left(input[1], 4) >> 2;
       โ”‚                                 -------------------
       โ”‚
    
    opened by manylov 1
Releases(v0.1.1)
Owner
zkWorks
zkWorks
Databento Binary Encoding (DBZ) - Fast message encoding and storage format for market data

dbz A library (dbz-lib) and CLI tool (dbz-cli) for working with Databento Binary Encoding (DBZ) files. Python bindings for dbz-lib are provided in the

Databento, Inc. 15 Nov 4, 2022
Noir, Circom, and Halo2 exercises for DSL workshop at ZKSummit10

ZKSummit10 - Exploring Noir, Circom, halo2 Workshop Prompt Write Noir, Halo2 and Circom circuits that constrain integer division i.e decimals are trun

Richard Liang 4 Sep 21, 2023
a universal meta-transliterator that can decipher arbitrary encoding schemas, built in pure Rust

transliterati a universal meta-transliterator that can decipher arbitrary encoding schemas, built in pure Rust what does it do? You give it this: ะ‘ะฐั€ะป

Catherine Koshka 7 Dec 21, 2022
A small command-line utility for encoding and decoding bech32 strings

A small command-line utility for encoding and decoding bech32 strings.

Charlie Moog 5 Dec 26, 2022
A tool to convert old and outdated "characters" into the superior Rustcii-Encoding.

rustcii A tool to convert old and outdated "characters" into the superior Rustcii-Encoding. Speak your mind. Blazingly ( ?? ) fast ( ?? ). Github | cr

null 8 Nov 16, 2022
High performance wlroots screen recording, featuring hardware encoding

wl-screenrec High performance wlroots based screen recorder. Uses dma-buf transfers to get surface, and uses the GPU to do both the pixel format conve

Russell Greene 32 Jan 21, 2023
Truly universal encoding detector in pure Rust - port of Python version

Charset Normalizer A library that helps you read text from an unknown charset encoding. Motivated by original Python version of charset-normalizer, I'

Nikolay Yarovoy 29 Oct 9, 2023
Base 32 + 64 encoding and decoding identifiers + bytes in rust, quickly

fast32 Base32 and base64 encoding in Rust. Primarily for integer (u64, u128) and UUID identifiers (behind feature uuid), as well as arbitrary byte arr

Chris Rogus 9 Dec 18, 2023
The Amp programming language: a language designed for building high performance systems.

A language designed for building high performance systems. Platform Support x86_64-pc-windows โœ… x86_64-unknown-linux โš ๏ธ untested x86_64-unknown-darwin

The Amp Programming Language 5 Mar 17, 2023
An Interpreter for Brainfuck programming language implemented in the Rust programming language with zero dependencies.

Brainfuck Hello, Visitor! Hey there, welcome to my project showcase website! It's great to have you here. I hope you're ready to check out some awesom

Syed Vilayat Ali Rizvi 7 Mar 31, 2023