0.1.2 • Published 1 year ago

@wingriders/apply-params-to-script v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@wingriders/apply-params-to-script

Simple isomorphic WASM wrapper around apply_params_to_script function from uplc. It enables you to take a parametrized script and apply the parameters to it.

Same functionality is also part of lucid, which integrates it further with the cardano-multiplatform-lib. So if you are already using CML that might be a better fit for you.

The goal of this library is to be a very thin WASM wrapper that communicates using buffers, and leaves the CBOR serialization of params and working with the script to you, so you can plug it into whatever toolchain you might be using.

Get started

npm

npm install @wingriders/apply-params-to-script

pnpm

pnpm add @wingriders/apply-params-to-script

yarn

yarn add @wingriders/apply-params-to-script

Usage

import {applyParamsToScript} from '@wingriders/apply-params-to-script'

// In this example our script is parametrized by one integer parameter
// so we'll apply the parameter 42 to this script

// This package works directly with the script CBOR, it doesn't accept double CBOR encoded scripts
const script = Buffer.from('your script cbor', 'hex')

// Our parameter needs to be wrapped in a PlutusData array
// so 42 becomes [42] which CBOR encoded is 81182A
const params = Buffer.from('81182A', 'hex')

// This returns Uint8Array type by default
const scriptWithAppliedParams = await applyParamsToScript(params, script)

// so we can cast it to a Buffer, so it's easier to work with
const scriptWithAppliedParamsBuffer = Buffer.from(scriptWithAppliedParams)

// No you can continue working with the script as you want to

You can also refer to the tests to see example usage. In case the application of the paramter is not successful, the function will throw an error.

Development

Building

To build this project you need to: 1. Install rust - refer to the their guide 2. Install wasm-pack - refer to the their guide 3. After that run wasm-pack build --target nodejs to build the library

Testing

First you need to build the project, after that you need to install the development dependencies using pnpm

pnpm

Then you can run the included tests with:

pnpm test

Contributing

This is a very simple and single focused library, but if you see any room for improvement, for example reducing the size of the outputted WASM bundle, or improving the isomorphic building and bundling, feel free to open a PR.

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago