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

@bsv/gasp

v0.1.2

Published

Graph Aware Sync Protocol

Downloads

198

Readme

GASP - Graph Aware Sync Protocol

GASP (Graph Aware Sync Protocol) is a protocol designed to synchronize transaction data between two parties in a blockchain environment. It ensures the legitimacy and completeness of transaction data using a recursive reconciliation method.

Features

  • Synchronizes transaction data between two parties.
  • Ensures legitimacy and completeness of transaction data.
  • Recursive reconciliation method.
  • Adaptable to various blockchain environments.
  • Emphasizes security, efficiency, and data integrity.

Installation

To install the GASP library, run:

npm i @bsv/gasp

Usage

Example Usage

For now, check out the GASP test suite to see how GASP works.

The below code is for reference only, and will probably not work (it is untested). Check back later for links to examples where GASP is implemented.

Here's a basic example demonstrating how to use the GASP library:

import { GASP, GASPStorage, GASPRemote, GASPInitialRequest, GASPNode } from '@bsv/gasp';

// Mock implementation of the storage interface for demonstration purposes
class ExampleGASPStorage implements GASPStorage {
  private utxos: Array<{ txid: string; outputIndex: number; rawTx: string; timestamp?: number }> = [];

  constructor(utxos: Array<{ txid: string; outputIndex: number; rawTx: string; timestamp?: number }>) {
    this.utxos = utxos;
  }

  async findKnownUTXOs(since: number): Promise<Array<{ txid: string; outputIndex: number }>> {
    return this.utxos
      .filter(utxo => utxo.timestamp && utxo.timestamp > since)
      .map(utxo => ({ txid: utxo.txid, outputIndex: utxo.outputIndex }));
  }

  async hydrateGASPNode(graphID: string, txid: string, outputIndex: number, metadata: boolean): Promise<GASPNode> {
    const found = this.utxos.find(utxo => utxo.txid === txid && utxo.outputIndex === outputIndex);
    if (!found) {
      throw new Error('UTXO not found');
    }
    return {
      graphID,
      rawTx: found.rawTx,
      outputIndex: found.outputIndex,
      // In a real implementation, you would return real proofs and metadata
      proof: metadata ? 'example_proof' : undefined,
      txMetadata: metadata ? 'example_tx_metadata' : undefined,
      outputMetadata: metadata ? 'example_output_metadata' : undefined,
    };
  }

  async findNeededInputs(tx: GASPNode): Promise<{ requestedInputs: Record<string, { metadata: boolean }> } | void> {
    // In a real scenario, this method would analyze the transaction inputs and determine if more information is needed
    return; // Assuming no additional inputs are needed for simplicity
  }

  async appendToGraph(tx: GASPNode, spentBy?: string): Promise<void> {
    console.log(`Appending transaction to graph: ${tx.txid} at output index ${tx.outputIndex}`);
  }

  async validateGraphAnchor(graphID: string): Promise<void> {
    console.log(`Validating graph anchor for graph ID: ${graphID}`);
  }

  async discardGraph(graphID: string): Promise<void> {
    console.log(`Discarding graph with ID: ${graphID}`);
  }

  async finalizeGraph(graphID: string): Promise<void> {
    console.log(`Finalizing graph with ID: ${graphID}`);
  }
}

// Example implementation of the remote interface
class ExampleGASPRemote implements GASPRemote {
  private remoteStorage: ExampleGASPStorage;

  constructor(remoteStorage: ExampleGASPStorage) {
    this.remoteStorage = remoteStorage;
  }

  async getInitialResponse(request: GASPInitialRequest): Promise<{ UTXOList: Array<{ txid: string; outputIndex: number }> }> {
    return { UTXOList: await this.remoteStorage.findKnownUTXOs(request.since) };
  }

  async requestNode(graphID: string, txid: string, outputIndex: number, metadata: boolean): Promise<GASPNode> {
    return this.remoteStorage.hydrateGASPNode(graphID, txid, outputIndex, metadata);
  }
}

// Initializing storages and remotes for two participants: Alice and Bob
const aliceStorage = new ExampleGASPStorage([
  { txid: 'tx1', outputIndex: 0, rawTx: '010000...', timestamp: 162005 },
  { txid: 'tx2', outputIndex: 1, rawTx: '020000...', timestamp: 162010 }
]);

const bobStorage = new ExampleGASPStorage([]);

const bobRemote = new ExampleGASPRemote(aliceStorage);
const alice = new GASP(aliceStorage, bobRemote);

// Simulate synchronization process
(async () => {
  try {
    await alice.sync();
    console.log('Synchronization between Alice and Bob completed successfully.');
  } catch (error) {
    console.error('Failed to synchronize:', error);
  }
})()

License

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