Skip to content
Snippets Groups Projects
README.md 2.19 KiB
Newer Older
# VCL - Vereign Javascript Library
Viktor Matanski's avatar
Viktor Matanski committed

1.  [Introduction](#introduction)
1.  [Setup](#setup)
1.  [Usage](#usage)
1.  [License](#license)

# Introduction 
Viktor Matanski's avatar
Viktor Matanski committed

Vereign’s JavaScript library is an asynchronous library that allows for digitally signing your email and in-browser documents, data encryption, and key-based authentication.

# Setup

Run `make` and get client library and iframe bundles from `javascript/dist` 

# Usage

Markin Igor's avatar
Markin Igor committed
Add library as inline script.
```html
<script type="text/javascript" src="./viamapi-client.js"/>
```

Initialize library
```js
// Target container used to append iframe
const containerId = "root";

// Required methods used to be called within iframe.
const methods = {
  onEvent(event) { console.log(event) }
};

// Iframe URL to connect 
const iframeUrl = "https://test.org/iframe";

// API url used to access endpoints
const apiUrl = "https://test.org/api";
Markin Igor's avatar
Markin Igor committed
 
const wopiUrl = "https://test.org/wopi";
Markin Igor's avatar
Markin Igor committed

Markin Igor's avatar
Markin Igor committed
this.library = setupViamAPI(containerId, methods, iframeUrl, apiUrl, wopiUrl);
Markin Igor's avatar
Markin Igor committed

this.library.then(lib => {
  this.listenerUUID = this.addListener({
    callback: function(event) {
      handleEvent(event);
    },
    filters: [
      "IdentityNotLoaded",
      "ActionConfirmedAndExecuted",
      "Authenticated"
    ]
  });

  lib.listIdentities().then(response => {
    this.setState({ identities: response.data });
  });
});
```

Markin Igor's avatar
Markin Igor committed
### Running

Markin Igor's avatar
Markin Igor committed
Run `make dev` to enter development mode. Library will be built with all Restful API endpoints and served from `localhost:9000`. If you edit JS libs code, it will be reloaded on the fly.

- Client being served from `http://localhost:9000/viamapi-client.js`
- Iframe being served from `http://localhost:9000/viamapi-iframe.html`

You can specify these URLs in the clients.

If you have to do changes in `main.go`, you need interrupt current process and do `make dev` again.

Markin Igor's avatar
Markin Igor committed
### CORS
Markin Igor's avatar
Markin Igor committed
Since libs and restful-api being served within different ports during the development, 
it worth mention that responses from restful-api in dev mode must include `"Access-Control-Allow-Origin": "http://localhost:9000"` 
and `"Access-Control-Allow-Headers": "*"` headers.

Markin Igor's avatar
Markin Igor committed

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.