npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iota/wallet-wasm

v1.0.0-alpha.1

Published

WebAssembly bindings for the IOTA wallet library

Downloads

5

Readme

IOTA Wallet Library - WebAssembly bindings

WebAssembly (Wasm) bindings for TypeScript/JavaScript to the wallet.rs Wallet library.

Which bindings to choose?

The wallet.rs Wallet library also offers dedicated Node.js bindings. The differences with this package are outlined below.

| | Wasm bindings | Node.js bindings | |:--------------|:-----------------:|:---------------------:| | Environment | Node.js, browsers | Node.js | | Installation | - | Rust, Cargo required* | | Performance | ✔️ | ✔️✔️ | | Ledger Nano | ❌ | ✔️ | | Rocksdb | ❌ | ✔️ | | Stronghold | ❌ | ✔️ |

*Node.js bindings only need to be compiled during npm install if a pre-compiled binary is not available for your platform.

tl;dr: Use the Node.js bindings if you can. The Wasm bindings are just more portable and support browser environments.

Requirements

  • One of the following Node.js versions: '16.x', '18.x';
  • wasm-bindgen (cargo install wasm-bindgen-cli);

Installation

  • Using npm:
$ npm i @iota/wallet-wasm
  • Using yarn:
$ yarn add @iota/wallet-wasm

Getting Started

After installing the library, you can create a Client instance and interface with it.

Node.js Usage

const { AccountManager, CoinType } = require('@iota/wallet-wasm/node');

const manager = new AccountManager({
      storagePath: './my-database',
      coinType: CoinType.Shimmer,
      clientOptions: {
          nodes: ['https://api.testnet.shimmer.network'],
      },
      secretManager: {
          mnemonic: "my development mnemonic",
      },
  });

const account = await manager.createAccount({
    alias: 'Alice',
});

account.getNodeInfo().then((nodeInfo) => {
  console.log(nodeInfo);
});

See the Node.js examples for more demonstrations, the only change needed is to import @iota/wallet-wasm/node instead of @iota/wallet.

Web Setup

Unlike Node.js, a few more steps are required to use this in the browser.

The library loads the compiled Wasm file with an HTTP GET request, so the wallet_wasm_bg.wasm file must be copied to the root of the distribution folder.

A bundler such as webpack or rollup is recommended.

Rollup

  • Install rollup-plugin-copy:
npm install rollup-plugin-copy --save-dev
  • Add the plugin to your rollup.config.js:
// Include the copy plugin.
import copy from 'rollup-plugin-copy'

// ...

// Add the copy plugin to the `plugins` array:
copy({
  targets: [{
    src: 'node_modules/@iota/wallet-wasm/web/wasm/wallet_wasm_bg.wasm',
    dest: 'public',
    rename: 'wallet_wasm_bg.wasm'
  }]
})

Webpack

  • Install copy-webpack-plugin:
npm install copy-webpack-plugin --save-dev
  • Add the plugin to your webpack.config.js:
// Include the copy plugin.
const CopyWebPlugin = require('copy-webpack-plugin');

// ...

experiments: {
    // futureDefaults: true, // includes asyncWebAssembly, topLevelAwait etc.
    asyncWebAssembly: true
}

// Add the copy plugin to the `plugins` array:
plugins: [
    new CopyWebPlugin({
      patterns: [
        {
          from: 'node_modules/@iota/wallet-wasm/web/wasm/wallet_wasm_bg.wasm',
          to: 'wallet_wasm_bg.wasm'
        }
      ]
    }),
    // other plugins...
]

Web Usage

import init, { AccountManager, CoinType } from "@iota/wallet-wasm/web";

init().then(() => {
  const manager = new AccountManager({
        storagePath: './my-database',
        coinType: CoinType.Shimmer,
        clientOptions: {
            nodes: ['https://api.testnet.shimmer.network'],
        },
        secretManager: {
            mnemonic: "my development mnemonic",
        },
    });

  const account = await manager.createAccount({
      alias: 'Alice',
  });

  account.getNodeInfo().then((nodeInfo) => {
    console.log(nodeInfo);
  });
}).catch(console.error);

// Default path to load is "wallet_wasm_bg.wasm", 
// but you can override it by passing a path explicitly.
//
// init("./static/wallet_wasm_bg.wasm").then(...)