Skip to content

Commit

Permalink
Update README and package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigoto-dev19 committed May 17, 2024
1 parent a0862a8 commit 4750bad
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
58 changes: 49 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
# O1JS Base64 Decode
# O1JS Base64 Encode/Decode

This repository offers a straightforward way to decode base64-encoded input bytes. It's designed to be easy to use and reliable tool for decoding base64 data in various projects using [o1js](https://docs.minaprotocol.com/zkapps/o1js/).
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/).

## How to use the package

1. Install the package
Install the package

```sh
npm install o1js-base64
```

2. Import the `base64Decode` function
Import the provable type `Bytes` from `o1js`

```typescript
import { base64Decode } from 'o1js-base64';
import { Bytes } from 'o1js';
```

3. Import the provable type `Bytes` from `o1js`
### Base64 Decode

1. Import the `base64Decode` function

```typescript
import { Bytes } from 'o1js';
import { base64Decode } from 'o1js-base64';
```

4. For the example of a **string** input:
2. For the example of a **string** input:

```typescript
const encodedB64 = Bytes.fromString('7xQM+vU=');
const decodedB64 = base64Decode(encodedB64, 5);
```

### Base64 Encode

1. Import the `base64Encode` function

```typescript
import { base64Encode } from 'o1js-base64';
```

2. For the example of a **string** input:

```typescript
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.
Expand All @@ -45,7 +64,8 @@ const decodedB64 = base64Decode(encodedB64, 5);

- For reference, consider this [snippet](https://github.com/Shigoto-dev19/o1js-base64/blob/main/src/run.ts#L7-L20), 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.
- Therefore, ensure the provable Byte types are accurately and deterministically assigned to match the input and output lengths.
- 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

Expand Down Expand Up @@ -74,18 +94,38 @@ 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](https://github.com/zkemail/zk-email-verify/blob/main/packages/circuits/lib/base64.circom)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "o1js-base64",
"version": "0.0.3",
"version": "0.1.0",
"description": "",
"author": "",
"license": "Apache-2.0",
Expand All @@ -12,6 +12,7 @@
"zkapp",
"base64",
"decode",
"encode",
"zk",
"zkSNARK",
"zero knowledge"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { base64Decode } from './base64.js';
export { base64Decode, base64Encode } from './base64.js';
export { calculateB64DecodedBytesLength } from './utils.js';

0 comments on commit 4750bad

Please sign in to comment.