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

blockchain-logger

v2.0.0

Published

Store logs in a blockchain structure

Downloads

8

Readme

blockchain-logger

logs

This project provides loggers which implement a basic blockchain structure. Data is put into the following block format and stored according to the chosen strategy:

{
  "data": "your data here",
  "meta": {
    "timestamp": "when it was created",
    "previousHash": "a sha256 hash of the previous block"
  },
  "hash": "a sha256 hash of this block’s contents"
}

Installation

yarn add blockchain-logger # or npm install blockchain-logger

Local file and Twitter loggers

Local file logger

This will store logs in date-stamped files in the directory of your choice.

import { LocalFileLogger } from 'blockchain-logger'

const logger = new LocalFileLogger({
  genesisHash: 'abc123',
  logPath: './logs/',
  logFilePrefix: 'actions',
})

Twitter logger

This will store logs in the alt-text of an image you repeatedly upload to your Twitter account. See @tweetblockchain for an example. (Click on an image for gallery view, and then inspect element to see the alt-text.)

import { TwitterLogger } from 'blockchain-logger'

const logger = new TwitterLogger({
    accessTokenKey: 'get-this-from-twitter',
    accessTokenSecret: 'get-this-from-twitter',
    baseImageLocation: './path/to/some/media/file.jpg',
    consumerKey: 'get-this-from-twitter',
    consumerSecret: 'get-this-from-twitter',
    genesisHash: 'abc123',
    screenName: '@handle',
  })
}

Log something

const data = { whatever: 'you want' }
logger.log(data)

Retrieve logs

logger.getLoggedData(ensureHashConsistency=true)

Blockchain logger

There’s also a logger for the Bitcoin blockchain or the Bitcoin Testnet. This stores data in transactions with an OP_RETURN output. Since the length of data that can be stored in such a transaction is limited to 80 bytes, this logger does not provide the blockchain properties of the other loggers, but can be used to store small amounts of data, or in conjunction with the other loggers to ensure integrity by storing hashes in a decentralised database.

Create a Blockchain logger

import { BlockchainLogger } from 'blockchain-logger'

const logger = new BlockchainLogger({
  maxFee: 5000, // satoshis
  prefix: 'BL', // prepended to everything you log (uses up characters!)
  privateKey: 'generate-this-using-secure-tools',
  testnet: true,
})

Only the private key is required. The private key is needed to sign the transactions created to store logs in OP_RETURN outputs. The transaction sends 0 satoshis to the OP_RETURN script, and the rest back to the input address, minus a mining fee.

The logger uses 21.co’s recommended fees to calculate what fee to pay for the logging transaction, but you can set a limit with maxFee.

Log something

logger.store('some text')
logger.store(Buffer.from('some arbitrary data'))

The limit is 80 bytes minus the length of your prefix (if you provided one).

Retrieve logs

logger.getLogs()

This returns an array of strings of text that has been stored using OP_RETURN transactions for the specified address, which include the prefix (if you provided one). The prefix is stripped off.

Interplay with other loggers

The local file and Twitter loggers can use the Blockchain logger to validate hash integrity. Just provide either one with an additional config option blockchainOptions, which should be a nested object containing the Blockchain logger options. E.g.:


import { LocalFileLogger } from 'blockchain-logger'

const logger = new LocalFileLogger({
  genesisHash: 'abc123',
  logPath: './logs/',
  logFilePrefix: 'actions',
  blockchainOptions: {
    maxFee: 5000,
    prefix: 'BL',
    privateKey: 'generate-this-using-secure-tools',
    testnet: true,
  },
})

Now if you call logger.getLoggedData(ensureHashConsistency=true), it will loop through the hashes stored on the Bitcoin/Testnet blockchain, and make sure that the hashes for your logs appear in that order on the relevant blockchain.