Skip to content

Commit

Permalink
fix: MET-1896 move lib folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-TaiTruong committed Mar 12, 2024
1 parent e7e2b3c commit 5788c2b
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<script src="/assets/env.global.js" type="text/javascript"></script>

<script type="module">
import init, { decode } from "/src/lib/pkg/uplc_js.js";
import init, { decode } from "/lib/pkg/uplc_js.js";
init().then(() => {
window.decodeUPLC = decode;
});
Expand Down
71 changes: 71 additions & 0 deletions lib/pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Project Name

UPLC-JS

## Overview

This project utilizes a WebAssembly module to decode flat data, providing a crucial tool for the Cardano Explorer. Leveraging Aiken's library https://github.com/aiken-lang/aiken, we've built a WebAssembly version of the decoder, making it accessible for web applications.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Update](#update)
- [Special Thanks](#special-thanks)

## Installation

Describe how to install and set up your project. Include any prerequisites, such as Rust and wasm-pack, if necessary.

1. Clone this repository:
```bash
git clone https://github.com/yourusername/yourproject.git
```
2. Install Rust:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
3. Install wasm-pack:
```bash
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
```
4. Build the project:
```bash
wasm-pack build --target web
```

## Usage

### Using the WebAssembly Module

1. Add the following script tag to your HTML file:
```html
<script type="module">
import { decode } from './pkg/uplc-js.js';
async function run() {
const yourFlat = "abc123";
const decoded = decode(yourFlat);
console.log(decoded)
}
run();
</script>
```
2. Call the exported functions from your JavaScript code:
```javascript
decode();
```

## Update

Now we are using uplc rust package version 1.0.14-alpha, you can update this version and rebuild by updating this version in Cargo.toml file.
```
uplc = { version = "1.0.14-alpha" }
```



## Special Thanks

Special thanks to Aiken for providing the library for decoding flat data. Now, we can build it to WebAssembly and use it in the Cardano Explorer.
17 changes: 17 additions & 0 deletions lib/pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "uplc-js",
"collaborators": [
"sotatek"
],
"version": "0.1.0",
"files": [
"uplc_js_bg.wasm",
"uplc_js.js",
"uplc_js.d.ts"
],
"module": "uplc_js.js",
"types": "uplc_js.d.ts",
"sideEffects": [
"./snippets/*"
]
}
39 changes: 39 additions & 0 deletions lib/pkg/uplc_js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} flat
* @returns {string}
*/
export function decode(flat: string): string;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly decode: (a: number, b: number, c: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {SyncInitInput} module
*
* @returns {InitOutput}
*/
export function initSync(module: SyncInitInput): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init(module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;

0 comments on commit 5788c2b

Please sign in to comment.