0.1.0 • Published 2 years ago

ur-wasm-js v0.1.0

Weekly downloads
-
License
MIT/Apache-2.0
Repository
github
Last release
2 years ago

ur-wasm-js

WASM/JS bindings for the ur-rust rust library

Getting started

Installation

Either build the library yourself with wasm-pack or install for npm

# Install from npm
npm i ur-wasm-js
# Or build from source
git clone https://github.com/lightning-digital-entertainment/ur-wasm-js
cd ur-wasm-js
wasm-pack build
# In your project dir
npm i path/to/pkg/inside/ur-wasm-js

Use it in Javascript

import * as ur from "ur-wasm-js";

const textdecoder = new TextDecoder();

const encoder = new ur.UrEncoder(
  "This is pretty awesome generating qr codes like this, isnt it?!?!?!?!?!?!?!?",
  5,
);
const decoder = new ur.UrDecoder();

while (!decoder.complete()) {
  const part = encoder.next_value();
  decoder.receive(part);
}

const messageAsBytes = decoder.message();
const messageAsString = textdecoder.decode(messageAsBytes);

console.log(messageAsString);
0.1.0

2 years ago