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

private-chat

v1.0.0

Published

A module to encrypt and decrypt private messages in the blockchain

Downloads

2

Readme

private-chat

This is a js library to encrypt and decrypt messages that are private between two or more adresses in the blockchain. To have more context refer to: https://github.com/emilianop11/private-blockchain-chat This payload is what the chat struct in the contract will store in the messages array. This library will act as a helper for the sender and receiver parties so they can encrypt and decrypt the messages that flow between them. Notice that all of this encryption and decryption is happening off chain, client side. On chain we are just storing the payload which is a base64 encoded stringified json with this format

{
    payloadHash: "md5 of unencrypted content"
    s: {
        k: "public key of sender",
        p: "encryptedDataString",
    }
    r: [{
        k: "public key of receiver",
        p: "encryptedDataString"
    }]
}

payloadHash: we prefer md5 instead of sha256 since its shorter. this field is used to make sure that the same string is being encrypted for all parties. So all decrypting parties can check the result they got against this hash.

"s" stands for sender "r" stands for receiver "p" stands for payload "k" stands for key

The encryption algorithm is as follows:

  1. take the desired message that the address wants to send, and compute the md5 hash of the content. This will be stored in payloadHash

  2. take the desired message that the address wants to send and encrypt it n + 1 times. Where n is the amount of receivers. Each encryption should use the recipients public key (from where do we get the pubkey of receipients? read below) and one for the sender.

  3. construct the json as described above and base64 encode it.

The decryption algorithm is as follows:

  1. take the incoming payload and base64 decode it

  2. search through the recipients (or senders) the matching public key that the decoding party owns.

  3. decrypt the "c" field using the recipients private key

  4. compute the md5 hash of the decrypted message and check that it equals the payloadHash

retrieving the publickey of an address that will receive the message

this is a problem that still needs an elegant solution. In the first implementation, an address before getting involved in a chat would need to call a smart contract (lets call it pubkey mapper) where they will send their public key as a parameter in the tx. The smart contract will store the mapping between the address and the pubkey. Any sender that wants to send a message to an address would need to query the contract to retrieve the pubkey. This also has the benefit that any address wont be able to receive messages until their owner explicitly called the pukkey mapper contract