Giter Site home page Giter Site logo

lacrypta / typescript-opentimestamps Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 1.1 MB

An OpenTimestamps client written in TypeScript

Home Page: https://lacrypta.ar/

License: Other

JavaScript 0.77% TypeScript 99.21% CSS 0.02%
bitcoin blockchain lib opentimestamps timechain

typescript-opentimestamps's Introduction

TypeScript OpenTimestamps (typescript-opentimestamps)

An OpenTimestamps client written in TypeScript

This project aims to provide a fully-tested, fully typed, OpenTimestamps Client. It currently supports stamping, upgrading, and verifying timestamps.

Table of Contents

  1. Background
  2. Install
  3. Usage
  4. API
  5. Contributing
  6. License

Background

The OpenTimestamps project currently hosts a number of Server, Client, and CLI implementations. This is our contribution to that list, adding TypeScript to it.

The project may be used as-is in Typescript directly, or it may be compiled and packaged for usage in the browser or NodeJS modules.

Install

Installing the library is straightforward:

npm add @lacrypta/typescript-opentimestamps
yarn add @lacrypta/typescript-opentimestamps
pnpm add @lacrypta/typescript-opentimestamps

The only run-time dependency is @noble/hashes.

Usage

Once installed the library can be directly imported:

import {
  type Timestamp,
  read as read,
  verify as verify,
  //
  verifiers,
} from '@lacrypta/typescript-opentimestamps';

const rawTimestamp: Uint8Array = Uint8Array.from(someTimestampBytes);
const timestamp: Timestamp = read(rawTimestamp);

verify(
  timestamp,
  verifiers,
).then(
  ({ attestations,  errors }: { attestations: Record<number, string[]>; errors: Record<string, Error[]> }): void => {
    Object.entries(attestations).forEach(([time, verifiers]: [string, string[]]): void => {
      console.log(`Verifiers ${verifiers.join(', ')} attest to this timestamp as of ${time}`);
    });
    Object.entries(errors).forEach(([verifier, errorList]: [string, Error[]]): void => {
      console.log(`${verifier} reported the following errors:`);
      errorList.forEach((error: Error): void => {
        console.log(error.message);
      });
    });
  },
);

API

This library exports the following types:

  • Timestamp: a type alias containing version, file hash, and validation tree information.

It exports the following functions:

  • info: obtain a human-readable description of the Timestamp's content.
  • canShrink: determine whether the given Timestamp can be shrunk to a single attestation chain.
  • canUpgrade: determine whether the given Timestamp ca be upgraded via a Calendar.
  • canVerify: determine whether the given Timestamp can be verified in the blockchain(s).
  • read: read a Uint8Array and transform it into a Timestamp if valid.
  • shrink: eliminate all but the oldest attestation found in the given Timestamp for the given chain.
  • submit: submit the given Timestamp to a Calendar for eventual inclusion in a blockchain.
  • upgrade: upgrade the given Timestamp via a Calendar so as to make it independently verifiable.
  • is: a TypeScript type predicate that simply applies validation to the given Timestamp.
  • validate: validate the given parameter and determine whether it is indeed a Timestamp object.
  • verify: verify the given Timestamp against the blockchain(s).
  • verifiers: a set of predefined lambda functions that will query the blockchain via explorer-provider APIs to check for the presence of a given Merkle root on-chain.
  • write: generate a Uint8Array consisting of the standard serialization of the given Timestamp value.

More in-depth information and prototypes can be found in the generated documentation.

Contributing

This project uses pnpm (think npm but faster), you'll need to install it if you haven't already.

You may clone the repository as usual:

git clone [email protected]:lacrypta/typescript-opentimestamps.git
cd typescript-opentimestamps

Now, simply install all dependencies:

pnpm install

We provide several pnpm commands for your convenience:

  • pnpm format: will run formatters and linters in all the codebase.
  • pnpm build: will build all targets (TypeScript type declarations included) in the /dist directory.
  • pnpm analyze: will analyze previous build.
  • pnpm doc: will generate internal and external documentation in the /dist directory.
  • pnpm clean: will remove the /dist directory entirely.
  • pnpm test: will run all tests and report coverage on the whole codebase.
  • pnpm reset: will run pnpm clean, and remove the /node_modules directory and pnpm-lock.yaml file, so as to completely reset the installation.

You'll probably want to run the tests first, build the documentation, and take it from there:

pnpm test
pnpm doc

Now navigate to /dist/docs/api/index.html (for the end-use documentation) or /dist/docs/internal/index.html (for developer documentation) and peruse the generated documentation at your leisure.

Please follow contribution guidelines at the GitHub repository, we encourage PRs!

License

GNU Affero General Public License v3.0 or later, see LICENSE.md.

typescript-opentimestamps's People

Contributors

mariano-perez-rodriguez avatar agustinkassis avatar dependabot[bot] avatar jjramirezn avatar

Stargazers

Fer avatar  avatar  avatar Rapax avatar Jona avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.