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

@iota/poex-tool

v2.1.0

Published

IOTA Signature command library/line tool

Downloads

15

Readme

Currently this package uses the experimental iota.js-library. While it is functionally complete, it will not be as heavily maintained in the future as iota.rs. However, as this package requires to compile within the browser, iota.js is the suitable option for now.

Documentation for @iota/poex-tool

@iota/poex-tool is a small library and a command line tool that wraps common functionalities that would be needed for building Proof of Existence (PoE) kind of apps This library have been used in this Proof of Existence PoC - code source

Getting started

npm i @iota/poex-tool

API

The Library exports a couple of APIs listed below:

  • async publish(fileHash, tag, provider): messageId-string
  • async fetch(messageId, provider): SHA-256-hash-string
  • async function verify(messageId, isBinaryInput, docpath, provider): boolean
  • hash(agnosticData, isBinaryInput): SHS-256-hash-string

Please not that the method signature of the publish-function changed from legacy to Chrysalis network! It now simply returns the messageId instead of an Transaction-array It also provides backwards compatibility with the legacy network to verify previously issued proofs.

  • async fetchLegacy(fetchOptions): SHA-256-hash-string
  • async verifyLegacy(fetchOptions, isBinaryInput, docpath): boolean

The legacy-fetch options can be viewed here

Sample codes

import { verify, hash, publish } from '@iota/poex-tool'
// ...

//Create the SHA-256 hash
const hash = hash("/home/myContract.doc", false);

const tag = "SAMPLE_MESSAGE_INDEX";
const provider = "PERMANODE_PROVIDER";
let messageId;
try {
  // Publish to Tangle and log the result
  messageId = await publish(hash, tag, provider)
  console.log(`Published PoE in messageId ${messageId}`)
  //In case this would have been a legacy operation: console.log(`TX Hash=${retArr[0].hash}`)
} 
catch(e) {
  console.log(`something went wrong ${e}`)
}



//...

// Verifying if the file matches the previous signed one then reflecting the result into a React state

const verified = await verify(messageId, false, "/home/myContract.doc", provider)
this.setState({ isLoading: false, docMutated: verified })

Command line tool

All the functions are available via command line tool - very useful for quick testing and instant Tangle interaction. Please open a console terminal and navigate to the /src directory. Here a quick demo:

Hashing the document is a necessary step but not necessarily done via this lib, however we highly recomend using it since it has been designed for easy usage/intergation with other functions:

> node cmd.js hash /home/myContract.doc
myContract.doc hash = afeea52aa284ffa2110f2feaa67fffff2

Please note when using this in web you have to use the -b flag to mark it as Binary data, otherwise it will be treated as path!

Then we issue a proof of existence of the file, meaning we save the current hash of the file, e.g. its current state, by publishing it on the Tangle.

> node cmd.js publish afeea52aa284ffa2110f2feaa67fffff2
MessageId = 0988e59a1ac52ac0d5397f48d9357f8c2819abf48235d964fdd89317475bff35  

We can now verify the file integrity by comparing a hash value with the hash-value stored in some proof-of-existence on the Tangle.

> node cmd.js verify /home/myContract.doc 0988e59a1ac52ac0d5397f48d9357f8c2819abf48235d964fdd89317475bff35 
true

For simplicity, we have used all the defaults parameters but we could also use all of these flags if we wanted too:

  • -p, --provider
  • -a, --address [for legacy operations]
  • -t, --tag

When using the CMD these network-related parameters of the functions default to these values

Now, let us use the fetch data from the Tangle.

> node cmd.js fetch 0988e59a1ac52ac0d5397f48d9357f8c2819abf48235d964fdd89317475bff35
Payload-data = afeea52aa284ffa2110f2feaa67fffff2

Again, here we have omitted all parameters thus using default ones.

Using the same default parameters, we were able to retrieve the exact data that was stored in the Tangle, now we could just calculate the file hash and compare it with this hash to determine whether the document has been changed since the PoE has been issued or not.

Even more easier we could also use a direct Command that performs a verify-operation for us:

> node cmd.js verify /home/myContract.doc
true

true means the document is the same as the original, and no-one has tampered with it!

That is it for now, we have covered the basic of Proof of existence using Tangle as a source of truth.