Giter Site home page Giter Site logo

joseph51d / owid-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from swan-community/owid-js

0.0 0.0 0.0 95 KB

Open Web Id (OWID) - a open source cryptographically secure shared web identifier schema implemented in JavaScript

License: Apache License 2.0

JavaScript 100.00%

owid-js's Introduction

Open Web Id

Open Web Id (OWID) JavaScript

Open Web Id (OWID) - a open source cryptographically secure shared web identifier schema implemented in JavaScript

Read the OWID project to learn more about the concepts before looking into this implementation.

Usage

To use OWID-js:

  • Add the owid.js file to your CDN or web application.
  • reference owid.js:
    <script src="https://<host>/owid.js" type="text/javascript"></script>
  • call the library:
    var o = new owid("[owid base 64 string]");
    o.verify().then(valid  => console.log(valid));

Interface

OWID-js library is used to construct owid objects and verify against other instances of OWID or base 64 encoded strings representing OWID trees.

Constructor

Create a new instance of OWID without any data. The instance can still be used to verify other OWIDs.

var o = new owid();

Create a new instance of OWID using a encrypted OWID.

var o = new owid("<encrypted data>");

Methods

Methods available to call on an instance of OWID.

Method Params Return Type Description
dateAsJavaScriptDate n/a Date Returns the OWID creation date as a JavaScript Date object.
payloadAsPrintable n/a string Returns the payload in hexadecimal.
payloadAsString n/a string Returns the payload as a string.
payloadAsBase64 n/a string Returns the payload as a base 64 string.
verify owid|owids[] Promise(bool) The verify method determines if the OWID instance is valid. It also takes an array of other OWID instances or strings that can be turned into OWIDs to verify the current OWID against.

Fields

Field Type Description
date number Returns the date and time the OWID was created in UTC as minutes since 2020-01-01 00:00
domain string Returns the creator of the OWID.
signature Uint8Array Returns the signature as byte array.

Examples

Verify an OWID.

var o = new owid("[encrypted data]");
 
console.log(o.payloadAsString()); // Returns the payload as a string.
console.log(o.payloadAsBase64()); // Returns the payload as a base 64 string.
console.log(o.domain); // Returns the creator of the OWID.
console.log(o.date); // Returns the date and time the OWID was created in UTC as minutes since `2020-01-01 00:00`.
console.log(o.signature); // Returns the signature as byte array.

o.verify()
    .then(valid  => console.log(valid)) // Uses a promise to determine if the OWID is valid.
    .catch(error => console.log(error));

Verify the supplier’s OWID that was created with the Offer ID.

var offerId = new owid("[encrypted Offer OWID]");

var supplier = new owid("[encrypted supplier OWID]");

supplier
    .verify(offerId)
    .then(valid => console.log(valid))
    .catch(error => console.log(error)); 

Verify multiple OWID base 64 strings.

var o = new owid("[encrypted data]");

o.verify(["encrypted data1", "encrypted data2", "encrypted data3"])
    .then(valid => console.log(valid))
    .catch(error => console.log(error));

Verify multiple OWID instances.

var o = new owid("[encrypted data]");

var offerId1 = new owid("[encrypted data1]");
var offerId2 = new owid("[encrypted data2]");
var offerId3 = new owid("[encrypted data3]");

o.verify([offerId1, offerId2, offerId3])
    .then(valid => console.log(valid))
    .catch(error => console.log(error));

Tests

Tests are performed using Jest.

Pre-requisites

  • Nodejs version 15.x or above
  • Yarn

Steps

Install yarn,

npm install --global yarn

Install Jest.

yarn install

Run tests.

yarn test

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.