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

@ahcpp/webmessage

v0.1.2

Published

Rust-Wasm library that stores a sequence of messages in browser's local storage with hashing and signatures.

Downloads

5

Readme

Webmessage

Webmessage is a library that stores a sequence of messages in browser's local storage. It uses techniques of hashing and digital signatures to ensure immutability of message sequence and the non-repudiation of the messages.

Build

Webmessage requires wasm-pack to build the package for web application.

To build, run

wasm-pack build --target web

The resulting package is saved into folder /pkg after successful build.

Test

The testing follows the guide rustwasm.

To test, run

wasm-pack test --chrome

Then, open the browser at localhost with pot 8000. The tests will be performed in browser with test results displayed on the webpage.

Example - Use in Web app (JavaScript)

In this example, the built package (i.e. files in the folder /pkg) is copied into the folder webmessage in the web app source folder.

import initWebMessage, { initAccount, signMessage, messages, validateMessages } from './webmessage';

initWebMessage().then(() => {
  // Module Initialized. Initialize the account (or use the account initialized before)
  console.log('WebMessage initialized, account: ', initAccount());

  // Sign a message that stores into local storage
  let signed_msg_stored = signMessage("chat 1", 'hello');
  console.log('WebMessage signed message', JSON.parse(signed_msg_stored));

  // Get number of messages stored
  let msgs = messages('chat 1');
  console.log('WebMessage messages count:', msgs.length);

  // Validate the stored messages (self checking)
  console.log('WebMessage validate messages', validateMessages('chat 1'));

  // Show the local storage size
  const {
    size
  } = new Blob(Object.values(localStorage))
  console.log('Local Storage Size: ', size);
})

Specification

The idea is to have users agree on the content of a message as well as the history of this message.

  • Signatures ensures the authenticity of the messages.
  • Attaching hash of previous message ensures the immutability of the history.
M <- (msg, prev_hash)
S <- Sig(Hash(M))
SM(n) <- (I, M, n, S) where 
    I is the identity of the message signer s.t. Verify(I, M, S)=True
    n is a sequence number

SM(n) is said to be valid if
    SM(n-1) is valid
    /\ Hash(SM(n-1)) is the prev_hash in M
    /\ there exists I' and S' where S' <- Sig(Hash(M)) and Verify(I', M, S')=True
    /\ SM(n) <- (I', M, n, S')

n starts with 0.

prev_hash of M in SM(0) is all-zeros.

Consideration

The library does not care about whether multiple sequences of messages share the same partial sequence. In other words, it does not prohibit the scenerio that there are two different signed messages over same previous hash or two different signers created messages over same previous hash because those signed messages could be considered as valid according to the specification.

The design reasonale is that, the creation of signature indicates the signer's intention to agree on something, which should not be simply ignored. Those signers should be responsible to any messages signed.

Limitations

Local Storage in browser is size-limited.

There are some improvement to make:

  • support multiple accounts
  • minimize the size of data to store
  • (welcome to add more)