babbage-kvstore

1.2.23 • Public • Published

Babbage-KVStore

A flexible and decentralized Key-Value storage and retrieval system, designed and engineered around the feature-rich and versatile Bitcoin SV (BSV).

npm version

Table Of Contents

Introduction

Babbage KVStore provides robust key-value storage functionality for your applications that leverages the power of Bitcoin SV's blockchain technology. By treating Bitcoin transactions (specifically UTXOs or Unspent Transaction Outputs) as your value store, you can create highly-distributed and verifiably-secure data storage for your application.

Installation

Simply use npm to include Babbage KVStore in your project:

npm install babbage-kvstore

Usage

Setting and Getting values

You can easily set up and utilize a key-value (KV) structure with Babbage. The set method takes in a key and a value, which are both strings. The get method retrieves the value associated with a key. Here is an example:

const { get, set } = require('babbage-kvstore');

// Set a value
set('Hello', 'World');

// Retrieve a value
console.log(get('Hello')); // Outputs: 'World'

Removing a Value

The remove method is used to delete a value in your KV store. All you need is the key:

const { remove } = require('babbage-kvstore');

// Remove a value
remove('Hello');

Retrieving Previous Values

getWithHistory lets you view previous versions of a value, allowing for an auditable log. This can be very powerful in several auditing and data tracking scenarios:

const { getWithHistory } = require('babbage-kvstore');

// Retrieve a value with history
console.log(getWithHistory('Hello')); // Outputs: entire history of 'Hello'

Configuration

None of these values are required, but you can use them to customize and greatly extend the behavior of KVStore.

Name Description Default Value
actionDescription Description for the Action that sets a value Set a value for (key)
outputDescription Description for the transaction output (line item) that represents a new value none
spendingDescription Description for the consumption of a previous value none
confederacyHost URL to the overlay network node that tracks the UTXOs you want to interact with 'https://confederacy.babbage.systems'
topics Overlay network node topics where UTXOs are stored and retrieved ['kvstore']
protocolID Sets the universe in wihch your keys and values are stored. Items in one universe can only be accessed in the same universe. [0, 'kvstore']
tokenAmount Sets the number of satoshis in each KVStore UTXO 1000
authriteConfig Parameters used to construct the Authrite client used to communicate with the overlay network node undefined
counterparty Allows the sharing and transfer of tokens between users (advanced) undefined
receiveFromCounterparty Move the token sent from the counterparty to self false
sendToCounterparty Move the token owned by self to the counterparty false
viewpoint Allows access to data repositories outside of one's own control. The viewpoint must be the identity public key of the repository owner. By default, only data from your own local viewpoint is accessible. localToSelf
doubleSpendMaxAttempts The max number of times it should reattempt an action if a double spend error is detected. 5
attemptCounter Keeps track of the current retry attempts if a double spend error is detected. 0

Applications and Use Cases

Due to its distributed, secure, and robust nature, Babbage KVStore can be used in various scenarios. A few key examples include:

  • Decentralized applications:
    • Enhanced user security
    • Non-fungible tokens (NFTs)
    • On-chain social media
    • Data provenance tracking
  • Auditing systems: With the use of the getWithHistory function, you can implement auditable logging and tracking systems.
  • Secure system settings: Store secure system environment settings.
  • Gaming: Keep track of game states and history.

API

Table of Contents

get

Gets a value from the store.

Parameters

  • key String The key for the value to get
  • defaultValue String The value returned when no token is found (optional, default undefined)
  • config Object The config object (see the config section) (optional, default {})

Returns Promise<String> The value from the store

getWithHistory

Gets a value from the store with history of token

Parameters

  • key String The key for the value to get
  • defaultValue String The value returned when no token is found (optional, default undefined)
  • config object The config object (see the config section) (optional, default {})

Returns Promise<object> The value from the store and history of the token

set

Sets a new value in the store, overwriting any existing value.

Parameters

  • key String The key for the value to set
  • value String The value to store
  • config Object The config object (see the config section) (optional, default {})

Returns Promise Promise that resolves when the value has been stored

remove

Deletes a value from the store.

Parameters

  • key String The key for the value to remove
  • config Object The config object (see the config section) (optional, default {})

Returns Promise Promise that resolves when the value has been deleted

License

The license for the code in this repository is the Open BSV License.

Package Sidebar

Install

npm i babbage-kvstore

Weekly Downloads

174

Version

1.2.23

License

Open BSV License

Unpacked Size

22.1 kB

Total Files

4

Last publish

Collaborators

  • tyeverett
  • braydude
  • tonesnotes