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.
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));
OWID-js library is used to construct owid objects and verify against other instances of OWID or base 64 encoded strings representing OWID trees.
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 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. |
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. |
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 are performed using Jest.
- Nodejs version 15.x or above
- Yarn
Install yarn,
npm install --global yarn
Install Jest.
yarn install
Run tests.
yarn test