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

bitdiary

v1.0.4

Published

BitDiary SDK

Downloads

7

Readme

BitDiary

BitDiary Protocol and SDK, for developers.

Usage

Install

Nodejs

npm install bitdiary
var BitDiary = require('bitdiary')

Browser

<script src="https://unpkg.com/bsv/bsv.min.js"></script>
<script src="https://unpkg.com/bitdiary/bitdiary.min.js"></script>

Init Diary

var diary = new BitDiary("Diary Private Key")

New/Update Diary

//var diaryEditKey = bsv.PrivateKey("Your Private Key")
var diaryEditKey = diary.newEditKey
var output = diary.getDiaryUpdateOutput("My Diary content", diaryEditKey)

/*
var tx = bsv.Transaction()
tx.addOutput(output)
tx.from(utxo)
....
tx.sign("UTXO Private Key")
*/

/*
moneyButton.render(MBDiv, {
    label: "Submit",
    ...,
    outputs: [{
        amount: output.satoshis / 100000000,
        script: output.script.toASM(),
        currency: 'BSV'
	},...]
})
*/

/*
// Sync
diary.readDiaries()
*/

Read Diaries

diary.readDiaries()

Or, read a single independent diary entry

//var diaryViewKey = bsv.PrivateKey().publcKey
var diaryIndex = 0
var diaryViewKey = diary.EditKey(diaryIndex).publicKey

diary.readDiary(diaryViewKey)

Protocol

BitDiary use Bitcoin Data Protocol pattern, and is pure OP_RETURN protocol.

Data is indexed by public key, encrypted by public key and signed by public key, so that you can find/decrypt/verify the data only if you have the public key.

The public key is derived from master key and is not used on blockchain. So the owner can have his privacy because no one knows the public key, or share diary entry with others by sharing public key.

Protocol structure is:

(OP_FALSE) OP_RETURN <Cryptic Prefix> <Encrypted Data> <Signature of plaintext Data>

CrypticPrefix

CrypticPrefix = Base64( Sha256( APP Prefix | PublicKey Hex ) )

Encrypted Data

KeyBuffer = Sha256( PublicKey Hex )

Key = KeyBuffer.slice(0,8)

IV = KeyBuffer.slice(8,16)

Encrypted Data = AES128CBCPKCS7( plaintext Data , Key, IV)

Signature

Signature = Base64( Secp256k1 Signature( plaintext Data, Sha256, Private Key ) )

Implement

It's important to have unused public key to protect privacy.

BitDiary use Method 42 to derive sub keys. However, BIP32(HD) is OK.

Key Derivation

BitDiary SDK use a bitcoin private key as master key.

BitDiary index diaries from 0 to n.

The diary entry's key is derived by Sha256Sha256(master key.childKey(String(index))) .

The reason why use sha256sha256 is to prevent retrieving master key from subkey.

Diaries Organize

BitDiary organize diaries from oldest to newest by 0 to n.

BitDiary SDK use binary algorithm to sync diaries.

The reason why use binary algorithm is to find n as soon as possible, so that new diary can be pushed without waiting for all diaries synced.

The basic search algorithm is

flag_foundN = false
index_lastValid = -1
index_lastInvalid = -1
index_current = 0

while(!flag_foundN){
	// check if current index valid
	if(valid(fetchDiary(index_current))){
		index_lastValid = index_current
	}else{
		index_lastInvalid = index_current
	}
	
	// next index to check
	if(index_lastInvalid != -1){
		flag_foundN = (index_lastValid == index_lastInvalid - 1)
		index_current = index_lastInvalid + (index_lastInvalid - index_lastValid) / 2
	}else{
		index_current = (index_current + 1) * 2 - 1
	}
}

n = index_lastValid

// fetch all diaries
for(i=n; i>-1; i--)fetchDiary(i)