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

factom-harmony-connect

v1.2.0

Published

Table of Contents =============== [INTRODUCTION](#Introduction) - [About This Document](#about) - [SDK Architecture Overview](#architecture)

Downloads

26

Readme

Table of Contents

INTRODUCTION

GETTING STARTED

METHODS

SAMPLE APPLICATION

INTRODUCTION

About This Document

This documentation is written for developers with a basic level of coding knowledge and familiarity of the JavaScript programming language.

Readers can find guidelines to quickly get started with building and using the JavaScript SDK for Factom Harmony Connect.

You can learn more about Factom Harmony Connect here.

This SDK is open source and can be accessed on Github here.

SDK Architecture Overview

architecture

FactomSDK Class: Manages SDK constructor, product connection and provides access to other layers.

Utilities: Contain functions shared between core components.

Core: Contains main components that interact with Connect API.

Request/Response Handler: Handles all requests/responses (HTTP / HTTPS) from Connect API before passing them to other components.

GETTING STARTED

This section contains a summary of the steps required to get started with JavaScript Connect SDK installation.

System Requirements

In order to use this JavaScript SDK, you will need the following tools:

  • NodeJS v8 or above: Please find the link here. Current node LTS version is 10.15.0.

  • NPM: Node installation will include Npm, which is responsible for dependencies management.

Installation

Node.js

npm install factom-harmony-connect

Usage

This SDK relies on Promises making it easier to handle the asynchronous requests made to the API.

For more details of a specific module, please refer to the Methods section.

If you want to understand how the SDK works in practice, refer to the Sample Application section.

Below is an example of how to use the SDK. Before executing any requests, you will need to instantiate an instance of the SDK. The required parameters include details about the application you will be using to authenticate your requests. If you do not have an application yet, you can get one here.

import Factom from "factom-harmony-connect"

const factomConnectSDK = new Factom({
  baseUrl: "YOUR API URL",
  accessToken: {
    appId: "YOUR APP ID",
    appKey: "YOUR APP KEY"
  },
});

When the Factom SDK is initialized, there will be an optional automaticSigning param, which defaults to true.

  • When this initial config is set to true as default, all chain and entry POST methods require passing the params: signerPrivateKey and signerChainId which will be used to create signed chains and entries, as per the Factom Signing Standard.

  • When this initial config is set to false, the FactomSDK will not sign the chains and entries that are created and therefore it does not require the params: signerPrivateKey and signerChainId.

The primary benefit of automaticSigning param is to encourage you to create chains and entries with unique signatures. Later on, you can validate that the chains or entries were created by you or that a certain user/device/ organization/etc. actually signed and published a certain message that you see in your chain.

Now that you have initialized the SDK, you can use the SDK's Methods, which will execute the necessary REST API calls on your behalf. Following the Promises notation, you should use Async/Await syntax or .then()/.catch in ES5 to handle successful and failed requests.

All Method calls take an object as a parameter.

Async/Await

const DoSomeThingWithData = async () => {
  try {
    const response = await factomConnectSDK.identities.create({
      name: [... < your names array > ]
      keys: [... < your public key array > ]
    })
    // handle the response
  } catch (error) {
    // handle the error
  }
}

ES5 syntax

function DoSomeThingWithData() {
  factomConnectSDK.identities.create({
    name: [... < your names array > ]
    keys: [... < your public key array > ]
  }).then((response) => {
    // handle the response
  }).catch((error) => {
    // handle the error
  })
}

Patterns to utilize the Factom SDK:

// Return a JSON chain object as is from the API.
const chain = await factomConnectSDK.chains.get({
  chainId: '5dc94c605769d8e9dac1423048f8e5a1182e575aab6d923207a3a8d15771ad63',
});

// Return JSON entries array as is from API.

const entries = await factomConnectSDK.chains.entries.list({
  chainId: '5dc94c605769d8e9dac1423048f8e5a1182e575aab6d923207a3a8d15771ad63',
});

// Return a JSON single entry object as is from the API.

const entry = await factomConnectSDK.chains.entries.get({
  chainId: '5dc94c605769d8e9dac1423048f8e5a1182e575aab6d923207a3a8d15771ad63',
  entryHash: 'e0e2b7f7920ce25c20cf98c13ae454566e7cda7bb815b8a9ca568320d7bdeb93',
});

Note: The SDK allows for override values that were set in the instatiation of the SDK on a per-method call basis. To override the parameters that were set in the instantiated SDK class, you may specify any of the following properties in the calls where these properties apply:

  • appId
  • appKey
  • baseUrl
  • automaticSigning

Example:

// Create a chain with automaticSigning turned off for one call
const createChainResponse = await factomConnectSDK.chains.create({
  externalIds: ["NotarySimulation", "CustomerChain", "cust123"],
  content: "This chain represents a notary service's customer in the NotarySimulation, a sample implementation provided as part of the Factom Harmony SDKs. Learn more here: https://docs.harmony.factom.com/docs/sdks-clients",
  automaticSigning: false

});

// Return a JSON chain object as is from the API with new appId, appKey, and baseUrl.
const chain = await FactomSDK.chains.get({
  chainId: '5dc94c605769d8e9dac1423048f8e5a1182e575aab6d923207a3a8d15771ad63',
  accessToken: {
    appId: "YOUR APP ID",
    appKey: "YOUR APP KEY"
  },
  baseUrl: "YOUR API URL"
});

// Return JSON entries array as is from API with new appId, appKey, and baseUrl.
const entries = await FactomSDK.chains.entries.list({
  chainId: '5dc94c605769d8e9dac1423048f8e5a1182e575aab6d923207a3a8d15771ad63',
  accessToken: {
    appId: "YOUR APP ID",
    appKey: "YOUR APP KEY"
  },
  baseUrl: "YOUR API URL"
});

// Return a JSON single entry object as is from the API with new appId, appKey, and baseUrl.
const entry = await FactomSDK.chains.entries.get({
  chainId: '5dc94c605769d8e9dac1423048f8e5a1182e575aab6d923207a3a8d15771ad63',
  entryHash: 'e0e2b7f7920ce25c20cf98c13ae454566e7cda7bb815b8a9ca568320d7bdeb93',
  accessToken: {
    appId: "YOUR APP ID",
    appKey: "YOUR APP KEY"
  },
  baseUrl: "YOUR API URL"
});

License

The Harmony Connect SDK is provided with an MIT License.

METHODS

identities

apiInfo

chains

anchors

receipts

utils

SAMPLE APPLICATION

Overview

architecture

This Sample App is created to illustrate some of the core methods of this SDK and a real-world business scenario of how it can be used.

Since the application is built as a standalone application with a backend SDK process, the reader should review the commented code here.

The concept of the Sample App is a simple Notary service with a business flow as follows:

  • A Notary service begins using Factom Harmony: To use Harmony, there should be at least 1 identity used when signing written data. So, to start, the app creates an identity’s chain for the Notary service.

  • The first customer purchases the Notary service’s new “Blockchain authentication” service tier: To track the customer’s documents, the app creates a signed chain for them, allowing easy retrieval for that customer’s records.

  • The customer requests notarization of the first document: The app creates a signed entry within the customer’s chain containing a hashed version of the document. At this time, the notary service should also be storing the document in a secure location.

  • The customer returns at a later date and the clerk retrieves the past work for this customer: The app searches the blockchain for the customer’s chain, and with that data, retrieves the chain. The SDK automatically validates the authenticity of this chain, which ensures that the Notary’s systems have not been tampered with and the blockchain data was submitted by the Notary service.

  • The customer requests the document that was notarized: The app searches for an entry in the chain validated in the step above and gets that entry info, then validates the authenticity of the signature used to sign that entry.

  • The document’s authenticity is validated: The app pulls out the document’s hash from the entry’s content and compares it against a freshly generated hash of a stored document.

    • Note: It is recommended that in a real-world scenario, scheduled tasks are run to validate the data for proactive validation.
  • A developer who had access to one of the keys leaves employment with the Notary company, so they carry out proactive security: The app replaces the old key pair that the employee had access to.

Installation

  1. Checkout the repository.
  2. Run npm install.
  3. Run npm run build.
  4. Navigate to folder cd ./sample-app.
  5. Open configure.js.
  6. Change configuration settings with your baseUrl, appId and appKey, which can be found or generated at https://account.factom.com.
  7. Run node server.js.
  8. Open localhost:8080 on your browser.

Usage

Starting screen: The app comes with a starting page where the user clicks the "Run Notary Simulation" button to run the app.

architecture

Simulating screen: Then the system will take some time to generate all responses by calling the Harmony Connect API through the JavaScript Connect SDK in Node JS backend.

architecture

Response screen: After the loading process is finished, the app will display relevant data with regard to this business flow.

architecture