Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@spacemesh/address-wasm

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spacemesh/address-wasm

WASM-Implementation of BECH32 address codec

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

@spacemesh/address-wasm

npm (scoped) npm bundle size (minified)

This package implements BECH32 address encoder and verifier.

To start using the library you need to install it first:

yarn add @spacemesh/address-wasm

And then start using it in your code:

import Bech32 from '@spacemesh/address-wasm'

(async () => {
  // Initialize wasm
  // Init function requires an HRPNetwork string
  // It will be called automatically on calling any of methods
  // in case it was not called before.
  Bech32.init();
  // Then you can setHRPNetwork:
  Bech32.setHRPNetwork('sm');

  // Get some public key
  const publicKey = Uint8Array.from([1, 2, 3, ..., 20]);
  // And generate address from it
  const addr = Bech32.generateAddress(publicKey);
  // You can also verify it
  console.log(Bech32.verify(addr)); // true
  // Then you can change HRP Network
  Bech32.setHRPNetwork('smtest');
  // And now previously generated address becomes invalid,
  // because it refers to different HRP network
  console.log(Bech32.verify(addr)); // false
  // And get byte-representation of the address:
  console.log(Bech32.parse(addr)); // [0, 0, 0, 0, 1, 2, ..., 20]
})();

// You can also call `verify`, `parse`, `generateAddress` methods
// with second argument: HRP. Then it will behave like pure function.
console.log(Bech32.generateAddress(publicKey, 'sm')); // 'sm1q...'
console.log(Bech32.generateAddress(publicKey, 'stest')); // 'stest1q...'
console.log(Bech32.verify(someAddr, 'stest')); // true / false

For contributors

This package contains Wasm implementation in golang, that uses spacemeshos/address implementation inside. Also, package includes Javascript wrapper over Wasm runner, that provides a clean facade for functions.

You will need to install Go (check out version in go.mod), NodeJS and yarn. Then you can just type:

make

To run different build processes — check out Makefile. For example to build only wasm file you can run

make gen-wasm

FAQs

Package last updated on 14 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc