Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigoto-dev19 committed May 6, 2024
1 parent eda7313 commit 13d525a
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
# Mina zkApp: Base64 O1js
# O1JS Base64 Decode

This template uses TypeScript.
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/).

## How to use the package

1. Install the package

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

2. Import the `base64Decode` function

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

3. Import the provable type `Bytes` from `o1js`

```typescript
import { Bytes } from 'o1js';
```

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

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

### Notes

- 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](https://github.com/Shigoto-dev19/o1js-base64/blob/main/src/base64.test.ts#L10-L17).

- If needed, you can refer to this [gist](https://gist.github.com/carlos-jenkins/3d28f9b05b5ae679ae5efe13d9cff9e8) 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](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.

## How to build

Expand All @@ -21,6 +66,35 @@ npm run testw # watch mode
npm run coverage
```

## How to benchmark

```sh
npm run benchmark
```

### Preview

| Summary | |
| --------------- | ---- |
| Total rows | 8081 |
| Generic | 1921 |
| EndoMulScalar | 88 |
| RangeCheck0 | 2112 |
| RangeCheck1 | 1056 |
| Zero | 1848 |
| ForeignFieldAdd | 1056 |

| Action | Time (s) |
| ------- | -------- |
| Compile | 1.985 |
| Prove | 15.496 |
| Verify | 1.021 |

## Acknowledgement

This repo is inspired by the [circom base64](https://github.com/zkemail/zk-email-verify/blob/main/packages/circuits/lib/base64.circom)
implementation.

## License

[Apache-2.0](LICENSE)

0 comments on commit 13d525a

Please sign in to comment.